mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 22:23:07 +00:00
Refactor validation to a single place
This commit is contained in:
parent
ec72f93480
commit
c1e6a28640
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Promise, _, events, form, helpers, resin, visuals;
|
||||
var Promise, _, events, form, resin, validation, visuals;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
events = require('resin-cli-events');
|
||||
|
||||
helpers = require('../utils/helpers');
|
||||
validation = require('../utils/validation');
|
||||
|
||||
exports.login = {
|
||||
signature: 'login',
|
||||
@ -39,7 +39,7 @@
|
||||
message: 'Email:',
|
||||
name: 'email',
|
||||
type: 'input',
|
||||
validate: helpers.validateEmail
|
||||
validate: validation.validateEmail
|
||||
}, {
|
||||
message: 'Password:',
|
||||
name: 'password',
|
||||
@ -89,7 +89,7 @@
|
||||
message: 'Email:',
|
||||
name: 'email',
|
||||
type: 'input',
|
||||
validate: helpers.validateEmail
|
||||
validate: validation.validateEmail
|
||||
}, {
|
||||
message: 'Username:',
|
||||
name: 'username',
|
||||
@ -98,12 +98,7 @@
|
||||
message: 'Password:',
|
||||
name: 'password',
|
||||
type: 'password',
|
||||
validate: function(input) {
|
||||
if (input.length < 8) {
|
||||
return 'Password should be 8 characters long';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
validate: validation.validatePassword
|
||||
}
|
||||
]).then(resin.auth.register).then(resin.auth.loginWithToken).tap(function() {
|
||||
return events.send('user.signup');
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Promise, _, capitano, chalk, child_process, os, validEmail;
|
||||
var Promise, _, capitano, chalk, child_process, os;
|
||||
|
||||
Promise = require('bluebird');
|
||||
|
||||
@ -15,21 +15,12 @@
|
||||
|
||||
chalk = require('chalk');
|
||||
|
||||
validEmail = require('valid-email');
|
||||
|
||||
exports.getGroupDefaults = function(group) {
|
||||
return _.chain(group).get('options').map(function(question) {
|
||||
return [question.name, question["default"]];
|
||||
}).object().value();
|
||||
};
|
||||
|
||||
exports.validateEmail = function(input) {
|
||||
if (!validEmail(input)) {
|
||||
return 'Email is not valid';
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.getOperatingSystem = function() {
|
||||
var platform;
|
||||
platform = os.platform();
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Promise, _, chalk, form, helpers, resin, visuals;
|
||||
var Promise, _, chalk, form, resin, validations, visuals;
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
chalk = require('chalk');
|
||||
|
||||
helpers = require('./helpers');
|
||||
validations = require('./validations');
|
||||
|
||||
exports.selectDeviceType = function() {
|
||||
return resin.models.device.getSupportedDeviceTypes().then(function(deviceTypes) {
|
||||
@ -81,12 +81,7 @@
|
||||
return form.ask({
|
||||
message: 'Choose a Name for your new application',
|
||||
type: 'input',
|
||||
validate: function(input) {
|
||||
if (input.length < 4) {
|
||||
return 'The application name should be at least 4 characters';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
validate: validation.validateApplicationName
|
||||
});
|
||||
});
|
||||
};
|
||||
|
27
build/utils/validation.js
Normal file
27
build/utils/validation.js
Normal file
@ -0,0 +1,27 @@
|
||||
(function() {
|
||||
var validEmail;
|
||||
|
||||
validEmail = require('valid-email');
|
||||
|
||||
exports.validateEmail = function(input) {
|
||||
if (!validEmail(input)) {
|
||||
return 'Email is not valid';
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.validatePassword = function(input) {
|
||||
if (input.length < 8) {
|
||||
return 'Password should be 8 characters long';
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.validateApplicationName = function(input) {
|
||||
if (input.length < 4) {
|
||||
return 'The application name should be at least 4 characters';
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -4,7 +4,7 @@ resin = require('resin-sdk')
|
||||
form = require('resin-cli-form')
|
||||
visuals = require('resin-cli-visuals')
|
||||
events = require('resin-cli-events')
|
||||
helpers = require('../utils/helpers')
|
||||
validation = require('../utils/validation')
|
||||
|
||||
exports.login =
|
||||
signature: 'login'
|
||||
@ -36,7 +36,7 @@ exports.login =
|
||||
message: 'Email:'
|
||||
name: 'email'
|
||||
type: 'input'
|
||||
validate: helpers.validateEmail
|
||||
validate: validation.validateEmail
|
||||
,
|
||||
message: 'Password:'
|
||||
name: 'password'
|
||||
@ -100,7 +100,7 @@ exports.signup =
|
||||
message: 'Email:'
|
||||
name: 'email'
|
||||
type: 'input'
|
||||
validate: helpers.validateEmail
|
||||
validate: validation.validateEmail
|
||||
,
|
||||
message: 'Username:'
|
||||
name: 'username'
|
||||
@ -109,11 +109,7 @@ exports.signup =
|
||||
message: 'Password:'
|
||||
name: 'password'
|
||||
type: 'password',
|
||||
validate: (input) ->
|
||||
if input.length < 8
|
||||
return 'Password should be 8 characters long'
|
||||
|
||||
return true
|
||||
validate: validation.validatePassword
|
||||
]
|
||||
|
||||
.then(resin.auth.register)
|
||||
|
@ -5,7 +5,6 @@ _.str = require('underscore.string')
|
||||
child_process = require('child_process')
|
||||
os = require('os')
|
||||
chalk = require('chalk')
|
||||
validEmail = require('valid-email')
|
||||
|
||||
exports.getGroupDefaults = (group) ->
|
||||
return _.chain(group)
|
||||
@ -15,12 +14,6 @@ exports.getGroupDefaults = (group) ->
|
||||
.object()
|
||||
.value()
|
||||
|
||||
exports.validateEmail = (input) ->
|
||||
if not validEmail(input)
|
||||
return 'Email is not valid'
|
||||
|
||||
return true
|
||||
|
||||
exports.getOperatingSystem = ->
|
||||
platform = os.platform()
|
||||
platform = 'osx' if platform is 'darwin'
|
||||
|
@ -4,7 +4,7 @@ form = require('resin-cli-form')
|
||||
visuals = require('resin-cli-visuals')
|
||||
resin = require('resin-sdk')
|
||||
chalk = require('chalk')
|
||||
helpers = require('./helpers')
|
||||
validations = require('./validations')
|
||||
|
||||
exports.selectDeviceType = ->
|
||||
resin.models.device.getSupportedDeviceTypes().then (deviceTypes) ->
|
||||
@ -53,11 +53,7 @@ exports.selectOrCreateApplication = ->
|
||||
form.ask
|
||||
message: 'Choose a Name for your new application'
|
||||
type: 'input'
|
||||
validate: (input) ->
|
||||
if input.length < 4
|
||||
return 'The application name should be at least 4 characters'
|
||||
|
||||
return true
|
||||
validate: validation.validateApplicationName
|
||||
|
||||
exports.selectProjectDirectory = ->
|
||||
resin.settings.get('projectsDirectory').then (projectsDirectory) ->
|
||||
|
19
lib/utils/validation.coffee
Normal file
19
lib/utils/validation.coffee
Normal file
@ -0,0 +1,19 @@
|
||||
validEmail = require('valid-email')
|
||||
|
||||
exports.validateEmail = (input) ->
|
||||
if not validEmail(input)
|
||||
return 'Email is not valid'
|
||||
|
||||
return true
|
||||
|
||||
exports.validatePassword = (input) ->
|
||||
if input.length < 8
|
||||
return 'Password should be 8 characters long'
|
||||
|
||||
return true
|
||||
|
||||
exports.validateApplicationName = (input) ->
|
||||
if input.length < 4
|
||||
return 'The application name should be at least 4 characters'
|
||||
|
||||
return true
|
Loading…
Reference in New Issue
Block a user