aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cli/actions.js12
-rwxr-xr-xcli/surfer.js2
2 files changed, 10 insertions, 4 deletions
diff --git a/cli/actions.js b/cli/actions.js
index 996ef7f..e9bbd9d 100644
--- a/cli/actions.js
+++ b/cli/actions.js
@@ -55,7 +55,7 @@ function collectFiles(filesOrFolders, options) {
55 return tmp; 55 return tmp;
56} 56}
57 57
58function login(uri) { 58function login(uri, options) {
59 var tmp = url.parse(uri); 59 var tmp = url.parse(uri);
60 if (!tmp.slashes) tmp = url.parse('https://' + uri); 60 if (!tmp.slashes) tmp = url.parse('https://' + uri);
61 61
@@ -63,8 +63,8 @@ function login(uri) {
63 63
64 console.log('Using server', server.cyan); 64 console.log('Using server', server.cyan);
65 65
66 var username = readlineSync.question('Username: '); 66 var username = options.username || readlineSync.question('Username: ');
67 var password = readlineSync.question('Password: ', { hideEchoBack: true, mask: '' }); 67 var password = options.password || readlineSync.question('Password: ', { hideEchoBack: true, mask: '' });
68 68
69 superagent.post(server + '/api/login').send({ username: username, password: password }).end(function (error, result) { 69 superagent.post(server + '/api/login').send({ username: username, password: password }).end(function (error, result) {
70 if (error && error.code === 'ENOTFOUND') { 70 if (error && error.code === 'ENOTFOUND') {
@@ -77,7 +77,11 @@ function login(uri) {
77 } 77 }
78 if (result.status !== 201) { 78 if (result.status !== 201) {
79 console.log('Login failed.\n'.red); 79 console.log('Login failed.\n'.red);
80 return login(uri); 80
81 // remove the password to avoid a login loop
82 delete options.password;
83
84 return login(uri, options);
81 } 85 }
82 86
83 // TODO remove at some point, this is just to clear the previous old version values 87 // TODO remove at some point, this is just to clear the previous old version values
diff --git a/cli/surfer.js b/cli/surfer.js
index ef3ed91..366d3c5 100755
--- a/cli/surfer.js
+++ b/cli/surfer.js
@@ -9,6 +9,8 @@ program.version(require('../package.json').version);
9 9
10program.command('login <url>') 10program.command('login <url>')
11 .description('Login to server') 11 .description('Login to server')
12 .option('--username [username]', 'Username (optional)')
13 .option('--password [password]', 'Password (optional)')
12 .action(actions.login); 14 .action(actions.login);
13 15
14program.command('logout') 16program.command('logout')