return tmp;
}
-function login(uri) {
+function login(uri, options) {
var tmp = url.parse(uri);
if (!tmp.slashes) tmp = url.parse('https://' + uri);
console.log('Using server', server.cyan);
- var username = readlineSync.question('Username: ');
- var password = readlineSync.question('Password: ', { hideEchoBack: true, mask: '' });
+ var username = options.username || readlineSync.question('Username: ');
+ var password = options.password || readlineSync.question('Password: ', { hideEchoBack: true, mask: '' });
+
+ if (!username || !password) process.exit(1);
superagent.post(server + '/api/login').send({ username: username, password: password }).end(function (error, result) {
if (error && error.code === 'ENOTFOUND') {
}
if (result.status !== 201) {
console.log('Login failed.\n'.red);
- return login(uri);
+
+ // remove the password to avoid a login loop
+ delete options.password;
+
+ return login(uri, options);
}
// TODO remove at some point, this is just to clear the previous old version values