diff --git a/build/actions/auth.js b/build/actions/auth.js index a6ba0e34..8c162908 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -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'); diff --git a/build/utils/helpers.js b/build/utils/helpers.js index 63dcdf90..93a55f80 100644 --- a/build/utils/helpers.js +++ b/build/utils/helpers.js @@ -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(); diff --git a/build/utils/patterns.js b/build/utils/patterns.js index 200b3153..9f280b59 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -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 }); }); }; diff --git a/build/utils/validation.js b/build/utils/validation.js new file mode 100644 index 00000000..5644caab --- /dev/null +++ b/build/utils/validation.js @@ -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); diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index 3ed239a9..6d67cdc9 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -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) diff --git a/lib/utils/helpers.coffee b/lib/utils/helpers.coffee index 366f0c8c..489feece 100644 --- a/lib/utils/helpers.coffee +++ b/lib/utils/helpers.coffee @@ -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' diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index 0f5860d4..2db990fc 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -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) -> diff --git a/lib/utils/validation.coffee b/lib/utils/validation.coffee new file mode 100644 index 00000000..e8320ed1 --- /dev/null +++ b/lib/utils/validation.coffee @@ -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