2015-01-15 17:10:14 +00:00
|
|
|
exports.login =
|
2015-10-21 12:18:14 +00:00
|
|
|
signature: 'login'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'login to resin.io'
|
2015-09-08 06:06:03 +00:00
|
|
|
help: '''
|
2015-01-15 17:10:14 +00:00
|
|
|
Use this command to login to your resin.io account.
|
2014-11-18 16:15:40 +00:00
|
|
|
|
2015-12-03 14:22:22 +00:00
|
|
|
This command will open your web browser and prompt you to authorize the CLI
|
|
|
|
from the dashboard.
|
|
|
|
|
|
|
|
If you don't have access to a web browser (e.g: running in a headless server),
|
|
|
|
you can fetch your authentication token from the preferences page and pass
|
|
|
|
the token option.
|
|
|
|
|
2015-12-12 04:09:31 +00:00
|
|
|
Alternatively, you can pass the `--credentials` boolean option to perform
|
|
|
|
a credential-based authentication, with optional `--email` and `--password`
|
|
|
|
options to avoid interactive behaviour (unless you have 2FA enabled).
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin login
|
2015-12-03 14:22:22 +00:00
|
|
|
$ resin login --token "..."
|
2015-12-12 04:09:31 +00:00
|
|
|
$ resin login --credentials
|
|
|
|
$ resin login --credentials --email johndoe@gmail.com --password secret
|
2015-09-08 06:06:03 +00:00
|
|
|
'''
|
2015-12-03 14:22:22 +00:00
|
|
|
options: [
|
2015-12-12 04:09:31 +00:00
|
|
|
{
|
|
|
|
signature: 'token'
|
|
|
|
description: 'auth token'
|
|
|
|
parameter: 'token'
|
|
|
|
alias: 't'
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'credentials'
|
|
|
|
description: 'credential-based login'
|
|
|
|
boolean: true
|
|
|
|
alias: 'c'
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'email'
|
|
|
|
parameter: 'email'
|
|
|
|
description: 'email'
|
|
|
|
alias: [ 'e', 'u' ]
|
|
|
|
}
|
|
|
|
{
|
|
|
|
signature: 'password'
|
|
|
|
parameter: 'password'
|
|
|
|
description: 'password'
|
|
|
|
alias: 'p'
|
|
|
|
}
|
2015-12-03 14:22:22 +00:00
|
|
|
]
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-15 17:10:14 +00:00
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
events = require('resin-cli-events')
|
2015-12-12 04:09:31 +00:00
|
|
|
form = require('resin-cli-form')
|
2015-12-07 14:32:24 +00:00
|
|
|
auth = require('resin-cli-auth')
|
2015-12-12 04:09:31 +00:00
|
|
|
validation = require('../utils/validation')
|
|
|
|
|
|
|
|
resin.settings.get('resinUrl').then (resinUrl) ->
|
|
|
|
console.log("Logging in to #{resinUrl}")
|
2015-12-07 14:32:24 +00:00
|
|
|
|
2015-12-03 14:22:22 +00:00
|
|
|
if options.token?
|
|
|
|
return resin.auth.loginWithToken(options.token)
|
2015-12-12 04:09:31 +00:00
|
|
|
else if options.credentials
|
|
|
|
return form.run [
|
|
|
|
message: 'Email:'
|
|
|
|
name: 'email'
|
|
|
|
type: 'input'
|
|
|
|
validate: validation.validateEmail
|
|
|
|
,
|
|
|
|
message: 'Password:'
|
|
|
|
name: 'password'
|
|
|
|
type: 'password'
|
|
|
|
],
|
|
|
|
override: options
|
|
|
|
.then(resin.auth.login)
|
|
|
|
.then(resin.auth.twoFactor.isPassed)
|
|
|
|
.then (isTwoFactorAuthPassed) ->
|
|
|
|
return if isTwoFactorAuthPassed
|
|
|
|
return form.ask
|
|
|
|
message: 'Two factor auth challenge:'
|
|
|
|
name: 'code'
|
|
|
|
type: 'input'
|
|
|
|
.then(resin.auth.twoFactor.challenge)
|
|
|
|
.catch ->
|
|
|
|
resin.auth.logout().then ->
|
|
|
|
throw new Error('Invalid two factor authentication code')
|
2015-12-03 14:22:22 +00:00
|
|
|
|
|
|
|
console.info('Connecting to the web dashboard')
|
|
|
|
return auth.login()
|
2015-08-13 18:50:36 +00:00
|
|
|
.then(resin.auth.whoami)
|
|
|
|
.tap (username) ->
|
|
|
|
console.info("Successfully logged in as: #{username}")
|
2015-08-31 21:39:48 +00:00
|
|
|
events.send('user.login')
|
2015-08-13 18:50:36 +00:00
|
|
|
.nodeify(done)
|
2014-12-24 15:14:30 +00:00
|
|
|
|
2015-01-15 17:10:14 +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
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin logout
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
resin = require('resin-sdk')
|
|
|
|
events = require('resin-cli-events')
|
|
|
|
|
2015-08-31 21:39:48 +00:00
|
|
|
resin.auth.logout().then ->
|
|
|
|
events.send('user.logout')
|
|
|
|
.nodeify(done)
|
2014-12-24 15:14:30 +00:00
|
|
|
|
2015-01-15 17:10:14 +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
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
If signup is successful, you'll be logged in to your new user automatically.
|
2014-12-12 14:25:32 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin signup
|
|
|
|
Email: me@mycompany.com
|
|
|
|
Username: johndoe
|
|
|
|
Password: ***********
|
2014-12-12 14:25:32 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin whoami
|
|
|
|
johndoe
|
|
|
|
'''
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
resin = require('resin-sdk')
|
|
|
|
form = require('resin-cli-form')
|
|
|
|
events = require('resin-cli-events')
|
|
|
|
validation = require('../utils/validation')
|
|
|
|
|
2015-08-13 18:50:36 +00:00
|
|
|
form.run [
|
|
|
|
message: 'Email:'
|
|
|
|
name: 'email'
|
|
|
|
type: 'input'
|
2015-10-21 13:37:25 +00:00
|
|
|
validate: validation.validateEmail
|
2015-08-13 18:50:36 +00:00
|
|
|
,
|
|
|
|
message: 'Username:'
|
|
|
|
name: 'username'
|
|
|
|
type: 'input'
|
|
|
|
,
|
|
|
|
message: 'Password:'
|
|
|
|
name: 'password'
|
|
|
|
type: 'password',
|
2015-10-21 13:37:25 +00:00
|
|
|
validate: validation.validatePassword
|
2015-08-13 18:50:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
.then(resin.auth.register)
|
|
|
|
.then(resin.auth.loginWithToken)
|
2015-08-31 21:39:48 +00:00
|
|
|
.tap ->
|
|
|
|
events.send('user.signup')
|
2015-08-13 18:50:36 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.whoami =
|
|
|
|
signature: 'whoami'
|
2015-08-13 18:50:36 +00:00
|
|
|
description: 'get current username and email address'
|
2015-01-15 17:10:14 +00:00
|
|
|
help: '''
|
2015-08-13 18:50:36 +00:00
|
|
|
Use this command to find out the current logged in username and email address.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin whoami
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
resin = require('resin-sdk')
|
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2015-08-13 18:50:36 +00:00
|
|
|
Promise.props
|
|
|
|
username: resin.auth.whoami()
|
|
|
|
email: resin.auth.getEmail()
|
2015-11-16 14:11:08 +00:00
|
|
|
url: resin.settings.get('resinUrl')
|
2015-08-13 18:50:36 +00:00
|
|
|
.then (results) ->
|
|
|
|
console.log visuals.table.vertical results, [
|
|
|
|
'$account information$'
|
|
|
|
'username'
|
|
|
|
'email'
|
2015-11-16 14:11:08 +00:00
|
|
|
'url'
|
2015-08-13 18:50:36 +00:00
|
|
|
]
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|