Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
options = {
default: 'frame'
};
const mongodbName = await Promptly.prompt(`MongoDB name: (${options.default})`, options);
// connect to db
const db = await MongoModels.connect({ uri: mongodbUri, db: mongodbName });
if (!db) {
throw Error('Could not connect to MongoDB.');
}
// get root user creds
const rootEmail = await Promptly.prompt('Root user email:');
const rootPassword = await Promptly.password('Root user password:');
// clear tables
await Promise.all([
Account.deleteMany({}),
AdminGroup.deleteMany({}),
Admin.deleteMany({}),
AuthAttempt.deleteMany({}),
Session.deleteMany({}),
Status.deleteMany({}),
User.deleteMany({})
]);
// setup root group
const createUser = (config: FactoryConfig) => async ({
defaultEmail,
defaultPassword,
rolesIds,
userType,
}: Options) => {
console.log(`--------------------------------------------------------`);
console.log(`Creating ${userType}...`);
const email = await promptly.prompt(
`Choose email [default: ${defaultEmail}]: `,
{ default: defaultEmail }
);
const password = await promptly.password(
`Choose password [default: ${defaultPassword}]: `,
{ default: defaultPassword }
);
const { service } = config;
console.log('Validating input...');
validateData(rules)({ email, password });
console.log('Input validated successfuly!');
console.log(`Creating ${userType}...`);
function signupRequest () {
let msg = 'Would you like to create a new account?';
Promptly.prompt(msg, { default: 'yes' }, (err, value) => {
if (err) {
console.log('Exception prompting input.');
return;
}
if (value === 'yes') {
console.log('Ok, let\'s create an account...');
signup();
} else {
console.log('Ok, please enter your credentials...');
configure();
}
});
}
.action(async (opts, args, rest) => {
const email = await promptly.prompt("Email: ")
const password = await promptly.password("Password: ")
const otp = await promptly.prompt("2FA code (if any): ", { default: "n/a", retry: false })
try {
const res = await axios.post(`${baseURL}/api/v1/sessions`, {
data: { attributes: { email, password, otp } }
})
processResponse(res, () => {
const homepath = homeConfigPath()
const credspath = path.join(homepath, "credentials.yml")
fs.writeFileSync(credspath, YAML.dump({ access_token: res.data.data.attributes.access_token }))
console.log("Wrote credentials at:", credspath)
})
} catch (e) {
if (e.response) {
console.log(e.response.data)
} else {
throw e
}
devHost: ['buildDirTests', function (done) {
Promptly.prompt('Local host: (localhost)', { default: 'localhost' }, done);
}],
devPort: ['devHost', function (done) {
function confirmPin (tokenLocation) {
app.logger.info("To Log-In, Visit: " + tokenLocation.bold.underline);
promptly.prompt("Enter PIN (you'll receive this upon log-in):", function (error, pin) {
requestOptions = {}
request.get(tokenLocation + '/' + pin, function (error, response, body) {
var data = JSON.parse(body);
if (error) {
app.logger.error(error);
}
else if (response.statusCode == 200) {
app.config.user.set('token', JSON.parse(body));
}
else if (data.error) {
app.logger.info(response.statusCode.red.bold + ' ' + response.message);
}
})
});
}
smtpHost: ['systemEmail', function (done, results) {
Promptly.prompt('SMTP host: (smtp.gmail.com)', { default: 'smtp.gmail.com' }, done);
}],
smtpPort: ['smtpHost', function (done, results) {
apiKey: ['username', (done) => {
Promptly.prompt('Api key', done);
}]
}, (err, results) => {
username: (done) => {
let options = state.username
? { default: state.username } : undefined;
Promptly.prompt('Username', options, done);
},
email: ['username', (done) => {
export const getAuthCode = (retry?: boolean): Promise =>
promptly.prompt(retry
? 'Wrong auth code, please re-enter: '
: 'Please enter auth code: ')