Allow login with token

This commit is contained in:
Juan Cruz Viotti 2015-03-11 14:37:24 -04:00
parent 6e978d74dd
commit 77695bb505
2 changed files with 18 additions and 69 deletions

View File

@ -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 <username> --password <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);
}

View File

@ -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 <username> --password <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'