mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-07 11:26:41 +00:00
Implement interactive signup form
This commit is contained in:
parent
33e209def5
commit
16ddd8ccb6
@ -1,5 +1,5 @@
|
||||
_ = require('lodash')
|
||||
url = require('url')
|
||||
open = require('open')
|
||||
async = require('async')
|
||||
resin = require('../resin')
|
||||
ui = require('../ui')
|
||||
@ -26,9 +26,20 @@ exports.logout = permissions.user ->
|
||||
resin.auth.logout()
|
||||
|
||||
exports.signup = ->
|
||||
signupUrl = resin.settings.get('urls.signup')
|
||||
absUrl = url.resolve(resin.settings.get('remoteUrl'), signupUrl)
|
||||
open(absUrl)
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
ui.widgets.register(callback)
|
||||
|
||||
(credentials, callback) ->
|
||||
resin.auth.register credentials, (error, token) ->
|
||||
return callback(error, credentials)
|
||||
|
||||
(credentials, callback) ->
|
||||
credentials = _.omit(credentials, 'email')
|
||||
resin.auth.login(credentials, callback)
|
||||
|
||||
], errors.handle)
|
||||
|
||||
exports.whoami = permissions.user ->
|
||||
resin.auth.whoami (error, username) ->
|
||||
|
@ -93,12 +93,19 @@ capitano.command
|
||||
help: '''
|
||||
Use this command to signup for a resin.io account.
|
||||
|
||||
In the future, this command may display a form in the terminal and handle
|
||||
the registration purely from the command line, but for reasons of simplicity,
|
||||
it opens your default web browser at the web based signup form.
|
||||
If signup is successful, you'll be logged in to your new user automatically.
|
||||
|
||||
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.
|
||||
|
||||
Examples:
|
||||
$ resin signup
|
||||
Email: me@mycompany.com
|
||||
Username: johndoe
|
||||
Password: ***********
|
||||
|
||||
$ resin whoami
|
||||
johndoe
|
||||
'''
|
||||
action: actions.auth.signup
|
||||
|
||||
|
@ -3,6 +3,30 @@ inquirer = require('inquirer')
|
||||
|
||||
exports.table = require('./table/table')
|
||||
|
||||
exports.register = (callback) ->
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: 'input'
|
||||
name: 'email'
|
||||
message: 'Email'
|
||||
}
|
||||
{
|
||||
type: 'input'
|
||||
name: 'username'
|
||||
message: 'Username'
|
||||
}
|
||||
{
|
||||
type: 'password'
|
||||
name: 'password'
|
||||
message: 'Password'
|
||||
validate: (input) ->
|
||||
if input.length < 8
|
||||
return 'Password should be 8 characters long'
|
||||
|
||||
return true
|
||||
}
|
||||
], _.partial(callback, null))
|
||||
|
||||
exports.login = (callback) ->
|
||||
inquirer.prompt([
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user