From 3ab7d3e24dba94fa31b88f255602bf6211aa7d7b Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Tue, 22 Sep 2015 16:38:46 -0700
Subject: Adds a check for email validity client-side when joining a team using
 a public link

---
 web/react/components/signup_user_complete.jsx | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

(limited to 'web/react/components/signup_user_complete.jsx')

diff --git a/web/react/components/signup_user_complete.jsx b/web/react/components/signup_user_complete.jsx
index 19c3b2d22..e77bde861 100644
--- a/web/react/components/signup_user_complete.jsx
+++ b/web/react/components/signup_user_complete.jsx
@@ -1,7 +1,7 @@
 // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
 // See License.txt for license information.
 
-var utils = require('../utils/utils.jsx');
+var Utils = require('../utils/utils.jsx');
 var client = require('../utils/client.jsx');
 var UserStore = require('../stores/user_store.jsx');
 var BrowserStore = require('../stores/browser_store.jsx');
@@ -31,13 +31,26 @@ export default class SignupUserComplete extends React.Component {
     handleSubmit(e) {
         e.preventDefault();
 
+        const providedEmail = React.findDOMNode(this.refs.email).value.trim();
+        if (!providedEmail) {
+            this.setState({nameError: '', emailError: 'This field is required', passwordError: ''});
+            return;
+        }
+
+        if (!Utils.isEmail(providedEmail)) {
+            this.setState({nameError: '', emailError: 'Please enter a valid email address', passwordError: ''});
+            return;
+        }
+
+        this.state.user.email = providedEmail;
+
         this.state.user.username = React.findDOMNode(this.refs.name).value.trim().toLowerCase();
         if (!this.state.user.username) {
             this.setState({nameError: 'This field is required', emailError: '', passwordError: '', serverError: ''});
             return;
         }
 
-        var usernameError = utils.isValidUsername(this.state.user.username);
+        var usernameError = Utils.isValidUsername(this.state.user.username);
         if (usernameError === 'Cannot use a reserved word as a username.') {
             this.setState({nameError: 'This username is reserved, please choose a new one.', emailError: '', passwordError: '', serverError: ''});
             return;
@@ -51,12 +64,6 @@ export default class SignupUserComplete extends React.Component {
             return;
         }
 
-        this.state.user.email = React.findDOMNode(this.refs.email).value.trim();
-        if (!this.state.user.email) {
-            this.setState({nameError: '', emailError: 'This field is required', passwordError: ''});
-            return;
-        }
-
         this.state.user.password = React.findDOMNode(this.refs.password).value.trim();
         if (!this.state.user.password || this.state.user.password .length < 5) {
             this.setState({nameError: '', emailError: '', passwordError: 'Please enter at least 5 characters', serverError: ''});
-- 
cgit v1.2.3-1-g7c22

