aboutsummaryrefslogtreecommitdiffhomepage
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/actions.js23
-rw-r--r--cli/config.js3
2 files changed, 13 insertions, 13 deletions
diff --git a/cli/actions.js b/cli/actions.js
index a862b4b..45656a6 100644
--- a/cli/actions.js
+++ b/cli/actions.js
@@ -22,12 +22,12 @@ var API = '/api/files/';
22var gQuery = {}; 22var gQuery = {};
23 23
24function checkConfig() { 24function checkConfig() {
25 if (!config.server() || !config.username() || !config.password()) { 25 if (!config.server() || !config.accessToken()) {
26 console.log('You have run "login" first'); 26 console.log('You have run "login" first');
27 process.exit(1); 27 process.exit(1);
28 } 28 }
29 29
30 gQuery = { username: config.username(), password: config.password() }; 30 gQuery = { access_token: config.accessToken() };
31 31
32 console.error('Using server %s', config.server().cyan); 32 console.error('Using server %s', config.server().cyan);
33} 33}
@@ -65,7 +65,7 @@ function login(uri) {
65 var username = readlineSync.question('Username: '); 65 var username = readlineSync.question('Username: ');
66 var password = readlineSync.question('Password: ', { hideEchoBack: true, mask: '' }); 66 var password = readlineSync.question('Password: ', { hideEchoBack: true, mask: '' });
67 67
68 superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { 68 superagent.post(server + '/api/login').send({ username: username, password: password }).end(function (error, result) {
69 if (error && error.code === 'ENOTFOUND') { 69 if (error && error.code === 'ENOTFOUND') {
70 console.log('Server %s not found.'.red, server.bold); 70 console.log('Server %s not found.'.red, server.bold);
71 process.exit(1); 71 process.exit(1);
@@ -74,18 +74,19 @@ function login(uri) {
74 console.log('Failed to connect to server %s'.red, server.bold, error.code); 74 console.log('Failed to connect to server %s'.red, server.bold, error.code);
75 process.exit(1); 75 process.exit(1);
76 } 76 }
77 if (result.status === 401) { 77 if (result.status !== 201) {
78 console.log('Login failed.'.red); 78 console.log('Login failed.\n'.red);
79 process.exit(1); 79 return login(uri);
80 } 80 }
81 81
82 config.set('server', server); 82 // TODO remove at some point, this is just to clear the previous old version values
83 config.set('username', username); 83 config.set('username', '');
84 config.set('password', '');
84 85
85 // TODO this is clearly bad and needs fixing 86 config.set('server', server);
86 config.set('password', password); 87 config.set('accessToken', result.body.accessToken);
87 88
88 gQuery = { username: username, password: password }; 89 gQuery = { access_token: result.body.accessToken };
89 90
90 console.log('Login successful'.green); 91 console.log('Login successful'.green);
91 }); 92 });
diff --git a/cli/config.js b/cli/config.js
index 68eae5f..bb5c4ad 100644
--- a/cli/config.js
+++ b/cli/config.js
@@ -16,8 +16,7 @@ exports = module.exports = {
16 16
17 // convenience 17 // convenience
18 server: function () { return get('server'); }, 18 server: function () { return get('server'); },
19 username: function () { return get('username'); }, 19 accessToken: function () { return get('accessToken'); }
20 password: function () { return get('password'); }
21}; 20};
22 21
23var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; 22var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;