From 90ddfe82ee0d140b7b328f5ddc5160adf5ea17c2 Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Wed, 6 Apr 2016 08:55:10 -0400
Subject: Fix email signup when LDAP is present

---
 webapp/components/signup_user_complete.jsx | 88 +++++++++++++++++-------------
 1 file changed, 51 insertions(+), 37 deletions(-)

(limited to 'webapp/components/signup_user_complete.jsx')

diff --git a/webapp/components/signup_user_complete.jsx b/webapp/components/signup_user_complete.jsx
index 629ac4a0a..fb3bf00ae 100644
--- a/webapp/components/signup_user_complete.jsx
+++ b/webapp/components/signup_user_complete.jsx
@@ -25,6 +25,7 @@ class SignupUserComplete extends React.Component {
 
         this.handleSubmit = this.handleSubmit.bind(this);
         this.inviteInfoRecieved = this.inviteInfoRecieved.bind(this);
+        this.handleLdapSignup = this.handleLdapSignup.bind(this);
 
         this.state = {
             data: '',
@@ -81,6 +82,23 @@ class SignupUserComplete extends React.Component {
             teamId: data.id
         });
     }
+
+    handleLdapSignup(method, loginId, password, token) {
+        Client.loginByLdap(this.state.teamName, loginId, password, token,
+            () => {
+                const redirect = Utils.getUrlParameter('redirect');
+                if (redirect) {
+                    browserHistory.push(decodeURIComponent(redirect));
+                } else {
+                    browserHistory.push('/' + this.state.teamName + '/channels/town-square');
+                }
+            },
+            (err) => {
+                this.setState({serverError: err.message});
+            }
+        );
+    }
+
     handleSubmit(e) {
         e.preventDefault();
 
@@ -368,7 +386,7 @@ class SignupUserComplete extends React.Component {
                             defaultMessage='With your LDAP credentials'
                         />
                     </strong></h5>
-                    <LoginLdap teamName={this.state.teamName}/>
+                    <LoginLdap submit={this.handleLdapSignup}/>
                 </div>
             );
         }
@@ -376,7 +394,7 @@ class SignupUserComplete extends React.Component {
         let emailSignup;
         if (global.window.mm_config.EnableSignUpWithEmail === 'true') {
             emailSignup = (
-                <div>
+                <form>
                     <div className='inner__content'>
                         {email}
                         {yourEmailIs}
@@ -432,7 +450,7 @@ class SignupUserComplete extends React.Component {
                             </button>
                         </p>
                     </div>
-                </div>
+                </form>
             );
         }
 
@@ -485,40 +503,36 @@ class SignupUserComplete extends React.Component {
                 </div>
                 <div className='col-sm-12'>
                     <div className='signup-team__container padding--less'>
-                        <div>
-                            <form>
-                                <img
-                                    className='signup-team-logo'
-                                    src={logoImage}
-                                />
-                                <h5 className='margin--less'>
-                                    <FormattedMessage
-                                        id='signup_user_completed.welcome'
-                                        defaultMessage='Welcome to:'
-                                    />
-                                </h5>
-                                <h2 className='signup-team__name'>{this.state.teamName}</h2>
-                                <h2 className='signup-team__subdomain'>
-                                    <FormattedMessage
-                                        id='signup_user_completed.onSite'
-                                        defaultMessage='on {siteName}'
-                                        values={{
-                                            siteName: global.window.mm_config.SiteName
-                                        }}
-                                    />
-                                </h2>
-                                <h4 className='color--light'>
-                                    <FormattedMessage
-                                        id='signup_user_completed.lets'
-                                        defaultMessage="Let's create your account"
-                                    />
-                                </h4>
-                                {signupMessage}
-                                {ldapSignup}
-                                {emailSignup}
-                                {serverError}
-                            </form>
-                        </div>
+                        <img
+                            className='signup-team-logo'
+                            src={logoImage}
+                        />
+                        <h5 className='margin--less'>
+                            <FormattedMessage
+                                id='signup_user_completed.welcome'
+                                defaultMessage='Welcome to:'
+                            />
+                        </h5>
+                        <h2 className='signup-team__name'>{this.state.teamName}</h2>
+                        <h2 className='signup-team__subdomain'>
+                            <FormattedMessage
+                                id='signup_user_completed.onSite'
+                                defaultMessage='on {siteName}'
+                                values={{
+                                    siteName: global.window.mm_config.SiteName
+                                }}
+                            />
+                        </h2>
+                        <h4 className='color--light'>
+                            <FormattedMessage
+                                id='signup_user_completed.lets'
+                                defaultMessage="Let's create your account"
+                            />
+                        </h4>
+                        {signupMessage}
+                        {ldapSignup}
+                        {emailSignup}
+                        {serverError}
                     </div>
                 </div>
             </div>
-- 
cgit v1.2.3-1-g7c22

