From e9ec6c67b2fe11df55f2ee7c9c6ec4cb5b7ce2d8 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 13 Aug 2015 15:22:22 -0400 Subject: [PATCH] Validate that email address is valid during signup. Fix #111 For this we use a third party dependency from npm called `valid-email` to avoid hardcoding and having to mantain a regular expression. --- build/actions/auth.js | 12 ++++++++++-- lib/actions/auth.coffee | 6 ++++++ package.json | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/build/actions/auth.js b/build/actions/auth.js index 4b3e6bb9..1eb3b992 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -1,5 +1,5 @@ (function() { - var TOKEN_URL, _, async, form, open, resin, settings, url, visuals; + var TOKEN_URL, _, async, form, open, resin, settings, url, validEmail, visuals; open = require('open'); @@ -17,6 +17,8 @@ visuals = require('resin-cli-visuals'); + validEmail = require('valid-email'); + TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences'); exports.login = { @@ -106,7 +108,13 @@ { message: 'Email:', name: 'email', - type: 'input' + type: 'input', + validate: function(input) { + if (!validEmail(input)) { + return 'Email is not valid'; + } + return true; + } }, { message: 'Username:', name: 'username', diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index d9b00ece..ba7b076a 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -6,6 +6,7 @@ resin = require('resin-sdk') settings = require('resin-settings-client') form = require('resin-cli-form') visuals = require('resin-cli-visuals') +validEmail = require('valid-email') TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences') @@ -139,6 +140,11 @@ exports.signup = message: 'Email:' name: 'email' type: 'input' + validate: (input) -> + if not validEmail(input) + return 'Email is not valid' + + return true , message: 'Username:' name: 'username' diff --git a/package.json b/package.json index 9b6089b2..bbd07b73 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "resin-vcs": "^2.0.0", "selfupdate": "^1.1.0", "underscore.string": "^3.1.1", - "user-home": "^2.0.0" + "user-home": "^2.0.0", + "valid-email": "0.0.2" } }