balena-cli/lib/actions/auth.coffee

100 lines
2.4 KiB
CoffeeScript
Raw Normal View History

_ = require('lodash-contrib')
2014-12-01 14:11:00 +00:00
url = require('url')
async = require('async')
2015-01-08 12:04:37 +00:00
resin = require('resin-sdk')
2014-12-05 16:00:15 +00:00
ui = require('../ui')
permissions = require('../permissions/permissions')
2014-12-22 19:48:11 +00:00
helpers = require('../helpers/helpers')
exports.login =
signature: 'login [credentials]'
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 a colon separated string, or you can omit the
credentials, in which case the tool will present you with an interactive login form.
Examples:
$ resin login username:password
$ resin login
'''
action: (params, options, done) ->
async.waterfall [
(callback) ->
if params.credentials?
return helpers.parseCredentials(params.credentials, callback)
else
return ui.widgets.login(callback)
2014-11-18 15:37:29 +00:00
(credentials, callback) ->
resin.auth.login(credentials, callback)
2014-11-18 15:48:05 +00:00
], done
2014-12-24 15:14:30 +00:00
exports.logout =
signature: 'logout'
description: 'logout from resin.io'
help: '''
Use this command to logout from your resin.io account.o
2014-12-24 15:14:30 +00:00
Examples:
$ resin logout
'''
action: permissions.user (params, options, done) ->
resin.auth.logout(done)
2014-12-24 15:14:30 +00:00
exports.signup =
signature: 'signup'
description: 'signup to resin.io'
help: '''
Use this command to signup for a resin.io account.
2014-12-24 15:14:30 +00:00
If signup is successful, you'll be logged in to your new user automatically.
2014-12-12 14:25:32 +00:00
TODO: We need to provide a non interactive way to use this command,
however it's not clear to me how to do it easily for now.
2014-12-12 14:25:32 +00:00
Examples:
$ resin signup
Email: me@mycompany.com
Username: johndoe
Password: ***********
2014-12-12 14:25:32 +00:00
$ resin whoami
johndoe
'''
action: (params, options, done) ->
async.waterfall([
(callback) ->
ui.widgets.register(callback)
(credentials, callback) ->
resin.auth.register credentials, (error, token) ->
return callback(error, credentials)
(credentials, callback) ->
resin.auth.login(credentials, callback)
], done)
exports.whoami =
signature: 'whoami'
description: 'get current username'
help: '''
Use this command to find out the current logged in username.
Examples:
$ resin whoami
'''
action: permissions.user (params, options, done) ->
resin.auth.whoami (error, username) ->
if not username?
return done(new Error('Username not found'))
console.log(username)