From 16ddd8ccb6649eca9fe09d8091031a440581df73 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 24 Dec 2014 11:14:30 -0400 Subject: [PATCH] Implement interactive signup form --- lib/actions/auth.coffee | 19 +++++++++++++++---- lib/app.coffee | 13 ++++++++++--- lib/ui/widgets/widgets.coffee | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index 772395c6..de797b9f 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -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) -> diff --git a/lib/app.coffee b/lib/app.coffee index 8ea4e6a4..9350bff9 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -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 diff --git a/lib/ui/widgets/widgets.coffee b/lib/ui/widgets/widgets.coffee index 22db1860..1ed436a8 100644 --- a/lib/ui/widgets/widgets.coffee +++ b/lib/ui/widgets/widgets.coffee @@ -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([ {