mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Redirect users to signup from login if they don't have an account
This commit is contained in:
parent
ef7e39450c
commit
4645ad06bc
@ -50,9 +50,10 @@ limitations under the License.
|
||||
],
|
||||
primary: true,
|
||||
action: function(params, options, done) {
|
||||
var Promise, _, auth, events, form, login, messages, patterns, resin;
|
||||
var Promise, _, auth, capitano, events, form, login, messages, patterns, resin;
|
||||
_ = require('lodash');
|
||||
Promise = require('bluebird');
|
||||
capitano = Promise.promisifyAll(require('capitano'));
|
||||
resin = require('resin-sdk');
|
||||
events = require('resin-cli-events');
|
||||
auth = require('resin-cli-auth');
|
||||
@ -78,6 +79,9 @@ limitations under the License.
|
||||
return auth.login();
|
||||
}
|
||||
return patterns.askLoginType().then(function(loginType) {
|
||||
if (loginType === 'register') {
|
||||
return capitano.runAsync('signup');
|
||||
}
|
||||
options[loginType] = true;
|
||||
return login(options);
|
||||
});
|
||||
@ -119,23 +123,26 @@ limitations under the License.
|
||||
form = require('resin-cli-form');
|
||||
events = require('resin-cli-events');
|
||||
validation = require('../utils/validation');
|
||||
return form.run([
|
||||
{
|
||||
message: 'Email:',
|
||||
name: 'email',
|
||||
type: 'input',
|
||||
validate: validation.validateEmail
|
||||
}, {
|
||||
message: 'Username:',
|
||||
name: 'username',
|
||||
type: 'input'
|
||||
}, {
|
||||
message: 'Password:',
|
||||
name: 'password',
|
||||
type: 'password',
|
||||
validate: validation.validatePassword
|
||||
}
|
||||
]).then(resin.auth.register).then(resin.auth.loginWithToken).tap(function() {
|
||||
return resin.settings.get('resinUrl').then(function(resinUrl) {
|
||||
console.log("\nRegistering to " + resinUrl);
|
||||
return form.run([
|
||||
{
|
||||
message: 'Email:',
|
||||
name: 'email',
|
||||
type: 'input',
|
||||
validate: validation.validateEmail
|
||||
}, {
|
||||
message: 'Username:',
|
||||
name: 'username',
|
||||
type: 'input'
|
||||
}, {
|
||||
message: 'Password:',
|
||||
name: 'password',
|
||||
type: 'password',
|
||||
validate: validation.validatePassword
|
||||
}
|
||||
]);
|
||||
}).then(resin.auth.register).then(resin.auth.loginWithToken).tap(function() {
|
||||
return events.send('user.signup');
|
||||
}).nodeify(done);
|
||||
}
|
||||
|
@ -79,6 +79,9 @@ limitations under the License.
|
||||
}, {
|
||||
name: 'Authentication token',
|
||||
value: 'token'
|
||||
}, {
|
||||
name: 'I don\'t have a Resin account!',
|
||||
value: 'register'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
@ -73,6 +73,7 @@ exports.login =
|
||||
action: (params, options, done) ->
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
capitano = Promise.promisifyAll(require('capitano'))
|
||||
resin = require('resin-sdk')
|
||||
events = require('resin-cli-events')
|
||||
auth = require('resin-cli-auth')
|
||||
@ -96,6 +97,10 @@ exports.login =
|
||||
return auth.login()
|
||||
|
||||
return patterns.askLoginType().then (loginType) ->
|
||||
|
||||
if loginType is 'register'
|
||||
return capitano.runAsync('signup')
|
||||
|
||||
options[loginType] = true
|
||||
return login(options)
|
||||
|
||||
@ -165,21 +170,24 @@ exports.signup =
|
||||
events = require('resin-cli-events')
|
||||
validation = require('../utils/validation')
|
||||
|
||||
form.run [
|
||||
message: 'Email:'
|
||||
name: 'email'
|
||||
type: 'input'
|
||||
validate: validation.validateEmail
|
||||
,
|
||||
message: 'Username:'
|
||||
name: 'username'
|
||||
type: 'input'
|
||||
,
|
||||
message: 'Password:'
|
||||
name: 'password'
|
||||
type: 'password',
|
||||
validate: validation.validatePassword
|
||||
]
|
||||
resin.settings.get('resinUrl').then (resinUrl) ->
|
||||
console.log("\nRegistering to #{resinUrl}")
|
||||
|
||||
form.run [
|
||||
message: 'Email:'
|
||||
name: 'email'
|
||||
type: 'input'
|
||||
validate: validation.validateEmail
|
||||
,
|
||||
message: 'Username:'
|
||||
name: 'username'
|
||||
type: 'input'
|
||||
,
|
||||
message: 'Password:'
|
||||
name: 'password'
|
||||
type: 'password',
|
||||
validate: validation.validatePassword
|
||||
]
|
||||
|
||||
.then(resin.auth.register)
|
||||
.then(resin.auth.loginWithToken)
|
||||
|
@ -62,6 +62,9 @@ exports.askLoginType = ->
|
||||
,
|
||||
name: 'Authentication token'
|
||||
value: 'token'
|
||||
,
|
||||
name: 'I don\'t have a Resin account!'
|
||||
value: 'register'
|
||||
]
|
||||
|
||||
exports.selectDeviceType = ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user