From 99dd271c06719de67b711329bc45c820504e0b2b Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Tue, 7 Jun 2016 18:16:32 -0400
Subject: Join team correctly when signing up with LDAP (#3287)

---
 webapp/components/signup_user_complete.jsx | 34 ++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 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 b3825f72f..a9d96e320 100644
--- a/webapp/components/signup_user_complete.jsx
+++ b/webapp/components/signup_user_complete.jsx
@@ -173,11 +173,24 @@ export default class SignupUserComplete extends React.Component {
             this.state.ldapPassword,
             null,
             () => {
-                GlobalActions.emitInitialLoad(
-                    () => {
-                        browserHistory.push('/select_team');
-                    }
-                );
+                if (this.props.location.query.id || this.props.location.query.h) {
+                    Client.addUserToTeamFromInvite(
+                        this.props.location.query.d,
+                        this.props.location.query.h,
+                        this.props.location.query.id,
+                        () => {
+                            this.finishSignup();
+                        },
+                        () => {
+                            // there's not really a good way to deal with this, so just let the user log in like normal
+                            this.finishSignup();
+                        }
+                    );
+
+                    return;
+                }
+
+                this.finishSignup();
             },
             (err) => {
                 if (err.id === 'ent.ldap.do_login.user_not_registered.app_error' || err.id === 'ent.ldap.do_login.user_filtered.app_error') {
@@ -205,6 +218,15 @@ export default class SignupUserComplete extends React.Component {
         );
     }
 
+    finishSignup() {
+        GlobalActions.emitInitialLoad(
+            () => {
+                GlobalActions.loadDefaultLocale();
+                browserHistory.push('/select_team');
+            }
+        );
+    }
+
     handleUserCreated(user, data) {
         track('signup', 'signup_user_02_complete');
         Client.loginById(
@@ -761,4 +783,4 @@ export default class SignupUserComplete extends React.Component {
             </div>
         );
     }
-}
\ No newline at end of file
+}
-- 
cgit v1.2.3-1-g7c22

