From 77695bb5059f069a897b24da21e9225efc366e2c Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 11 Mar 2015 14:37:24 -0400 Subject: [PATCH] Allow login with token --- build/actions/auth.js | 38 ++++++-------------------------- lib/actions/auth.coffee | 49 +++++++++-------------------------------- 2 files changed, 18 insertions(+), 69 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index e0fbee51..2ed11803 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -28,42 +28,18 @@ }; exports.login = { - signature: 'login', + signature: 'login [token]', description: 'login to resin.io', - help: 'Use this command to login to your resin.io account.\nYou need to login before you can use most of the commands this tool provides.\n\nYou can pass your credentials as `--username` and `--password` options, or you can omit the\ncredentials, in which case the tool will present you with an interactive login form.\n\nExamples:\n\n $ resin login --username --password \n $ resin login', - options: [ - { - signature: 'username', - parameter: 'username', - description: 'user name', - alias: 'u' - }, { - signature: 'password', - parameter: 'password', - description: 'user password', - alias: 'p' - } - ], + help: 'Use this command to login to your resin.io account.\n\nTo login, you need your token, which is accesible from the preferences page:\n\n https://dashboard.resin.io/preferences?tab=details\n\nExamples:\n\n $ resin login\n $ resin login "eyJ0eXAiOiJKV1Qi..."', action: function(params, options, done) { - var hasOptionCredentials; - hasOptionCredentials = !_.isEmpty(options); - if (hasOptionCredentials) { - if (!options.username) { - return done(new Error('Missing username')); - } - if (!options.password) { - return done(new Error('Missing password')); - } - } return async.waterfall([ function(callback) { - if (hasOptionCredentials) { - return callback(null, options); - } else { - return visuals.widgets.login(callback); + if (params.token != null) { + return callback(null, params.token); } - }, function(credentials, callback) { - return resin.auth.login(credentials, callback); + return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback); + }, function(token, callback) { + return resin.auth.loginWithToken(token, done); } ], done); } diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index c6161002..0c081bff 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -22,58 +22,31 @@ exports.whoami = return done() exports.login = - signature: 'login' + signature: 'login [token]' description: 'login to resin.io' help: ''' Use this command to login to your resin.io account. - You need to login before you can use most of the commands this tool provides. - You can pass your credentials as `--username` and `--password` options, or you can omit the - credentials, in which case the tool will present you with an interactive login form. + To login, you need your token, which is accesible from the preferences page: + + https://dashboard.resin.io/preferences?tab=details Examples: - $ resin login --username --password $ resin login + $ resin login "eyJ0eXAiOiJKV1Qi..." ''' - options: [ - { - signature: 'username' - parameter: 'username' - description: 'user name' - alias: 'u' - } - { - signature: 'password' - parameter: 'password' - description: 'user password' - alias: 'p' - } - ] action: (params, options, done) -> - - hasOptionCredentials = not _.isEmpty(options) - - if hasOptionCredentials - - if not options.username - return done(new Error('Missing username')) - - if not options.password - return done(new Error('Missing password')) - - async.waterfall [ + async.waterfall([ (callback) -> - if hasOptionCredentials - return callback(null, options) - else - return visuals.widgets.login(callback) + return callback(null, params.token) if params.token? + visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback) - (credentials, callback) -> - resin.auth.login(credentials, callback) + (token, callback) -> + resin.auth.loginWithToken(token, done) - ], done + ], done) exports.logout = signature: 'logout'