From 15397f71b86c50f306e5116f557c9f290b348b1a Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 9 Feb 2017 13:16:41 +0100 Subject: Add cli logout command --- cli/actions.js | 18 ++++++++++++++++++ cli/surfer.js | 4 ++++ 2 files changed, 22 insertions(+) (limited to 'cli') diff --git a/cli/actions.js b/cli/actions.js index 45656a6..065e700 100644 --- a/cli/actions.js +++ b/cli/actions.js @@ -1,6 +1,7 @@ 'use strict'; exports.login = login; +exports.logout = logout; exports.put = put; exports.get = get; exports.del = del; @@ -92,6 +93,23 @@ function login(uri) { }); } +function logout() { + checkConfig(); + + superagent.post(config.server() + '/api/logout').query(gQuery).end(function (error, result) { + if (result && result.statusCode !== 200) console.log('Failed to logout: ' + result.statusCode); + if (error) console.log(error); + + // TODO remove at some point, this is just to clear the previous old version values + config.set('username', ''); + config.set('password', ''); + config.set('server', ''); + config.set('accessToken', ''); + + console.log('Done'.green); + }); +} + function put(filePath, otherFilePaths, options) { checkConfig(); diff --git a/cli/surfer.js b/cli/surfer.js index 46e5ba5..ef3ed91 100755 --- a/cli/surfer.js +++ b/cli/surfer.js @@ -11,6 +11,10 @@ program.command('login ') .description('Login to server') .action(actions.login); +program.command('logout') + .description('Logout from server') + .action(actions.logout); + program.command('put [files...]') .option('-a --all', 'Also include hidden files and folders.', false) .description('Put a file, last argument is destination if provided') -- cgit v1.2.3