From 9b7a26fc3708ac42d7d29c4329adbde465d29220 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 9 Feb 2017 13:02:41 +0100 Subject: Send username/password in body and fix cli --- cli/actions.js | 23 ++++++++++++----------- cli/config.js | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'cli') 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/'; var gQuery = {}; function checkConfig() { - if (!config.server() || !config.username() || !config.password()) { + if (!config.server() || !config.accessToken()) { console.log('You have run "login" first'); process.exit(1); } - gQuery = { username: config.username(), password: config.password() }; + gQuery = { access_token: config.accessToken() }; console.error('Using server %s', config.server().cyan); } @@ -65,7 +65,7 @@ function login(uri) { var username = readlineSync.question('Username: '); var password = readlineSync.question('Password: ', { hideEchoBack: true, mask: '' }); - superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { + superagent.post(server + '/api/login').send({ username: username, password: password }).end(function (error, result) { if (error && error.code === 'ENOTFOUND') { console.log('Server %s not found.'.red, server.bold); process.exit(1); @@ -74,18 +74,19 @@ function login(uri) { console.log('Failed to connect to server %s'.red, server.bold, error.code); process.exit(1); } - if (result.status === 401) { - console.log('Login failed.'.red); - process.exit(1); + if (result.status !== 201) { + console.log('Login failed.\n'.red); + return login(uri); } - config.set('server', server); - config.set('username', username); + // TODO remove at some point, this is just to clear the previous old version values + config.set('username', ''); + config.set('password', ''); - // TODO this is clearly bad and needs fixing - config.set('password', password); + config.set('server', server); + config.set('accessToken', result.body.accessToken); - gQuery = { username: username, password: password }; + gQuery = { access_token: result.body.accessToken }; console.log('Login successful'.green); }); 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 = { // convenience server: function () { return get('server'); }, - username: function () { return get('username'); }, - password: function () { return get('password'); } + accessToken: function () { return get('accessToken'); } }; var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; -- cgit v1.2.3