From d7cdcf082fab6c0cb7c2fe4bed821bd1a8000e69 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Mon, 8 Feb 2016 07:26:10 -0500
Subject: Convering client to react-router.

---
 web/react/components/login.jsx | 222 +++++++++++++++++++++++------------------
 1 file changed, 125 insertions(+), 97 deletions(-)

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

diff --git a/web/react/components/login.jsx b/web/react/components/login.jsx
index 581b8e0b5..30c8ffe4f 100644
--- a/web/react/components/login.jsx
+++ b/web/react/components/login.jsx
@@ -6,82 +6,118 @@ import LoginUsername from './login_username.jsx';
 import LoginLdap from './login_ldap.jsx';
 
 import * as Utils from '../utils/utils.jsx';
+import * as Client from '../utils/client.jsx';
 import Constants from '../utils/constants.jsx';
+import TeamStore from '../stores/team_store.jsx';
 
 import {FormattedMessage} from 'mm-intl';
+import {browserHistory} from 'react-router';
 
 export default class Login extends React.Component {
     constructor(props) {
         super(props);
 
-        this.state = {};
+        this.getStateFromStores = this.getStateFromStores.bind(this);
+        this.onTeamChange = this.onTeamChange.bind(this);
+
+        this.state = this.getStateFromStores();
+    }
+    componentDidMount() {
+        TeamStore.addChangeListener(this.onTeamChange);
+        Client.getMeLoggedIn((data) => {
+            if (data && data.logged_in !== 'false') {
+                browserHistory.push('/' + this.props.params.team + '/channels/town-square');
+            }
+        });
+    }
+    componentWillUnmount() {
+        TeamStore.removeChangeListener(this.onTeamChange);
+    }
+    getStateFromStores() {
+        return {
+            currentTeam: TeamStore.getByName(this.props.params.team)
+        };
+    }
+    onTeamChange() {
+        this.setState(this.getStateFromStores());
     }
     render() {
-        const teamDisplayName = this.props.teamDisplayName;
-        const teamName = this.props.teamName;
+        const currentTeam = this.state.currentTeam;
+        if (currentTeam == null) {
+            return <div/>;
+        }
+
+        const teamDisplayName = currentTeam.display_name;
+        const teamName = currentTeam.name;
 
         let loginMessage = [];
         if (global.window.mm_config.EnableSignUpWithGitLab === 'true') {
             loginMessage.push(
-                    <a
-                        className='btn btn-custom-login gitlab'
-                        key='gitlab'
-                        href={'/' + teamName + '/login/gitlab'}
-                    >
-                        <span className='icon'/>
-                        <span>
-                            <FormattedMessage
-                                id='login.gitlab'
-                                defaultMessage='with GitLab'
-                            />
-                        </span>
-                    </a>
+                <a
+                    className='btn btn-custom-login gitlab'
+                    key='gitlab'
+                    href={'/api/v1/oauth/gitlab/login?team=' + encodeURIComponent(teamName)}
+                >
+                    <span className='icon'/>
+                    <span>
+                        <FormattedMessage
+                            id='login.gitlab'
+                            defaultMessage='with GitLab'
+                        />
+                    </span>
+                </a>
             );
         }
 
         if (global.window.mm_config.EnableSignUpWithGoogle === 'true') {
             loginMessage.push(
-                    <a
-                        className='btn btn-custom-login google'
-                        key='google'
-                        href={'/' + teamName + '/login/google'}
-                    >
-                        <span className='icon'/>
-                        <span>
-                            <FormattedMessage
-                                id='login.google'
-                                defaultMessage='with Google Apps'
-                            />
-                        </span>
-                    </a>
-           );
+                <a
+                    className='btn btn-custom-login google'
+                    key='google'
+                    href={'/api/v1/oauth/google/login?team=' + encodeURIComponent(teamName)}
+                >
+                    <span className='icon'/>
+                    <span>
+                        <FormattedMessage
+                            id='login.google'
+                            defaultMessage='with Google Apps'
+                        />
+                    </span>
+                </a>
+            );
         }
 
         const extraParam = Utils.getUrlParameter('extra');
         let extraBox = '';
         if (extraParam) {
-            let msg;
             if (extraParam === Constants.SIGNIN_CHANGE) {
-                msg = (
-                    <FormattedMessage
-                        id='login.changed'
-                        defaultMessage=' Sign-in method changed successfully'
-                    />
+                extraBox = (
+                    <div className='alert alert-success'>
+                        <i className='fa fa-check'/>
+                        <FormattedMessage
+                            id='login.changed'
+                            defaultMessage=' Sign-in method changed successfully'
+                        />
+                    </div>
                 );
             } else if (extraParam === Constants.SIGNIN_VERIFIED) {
-                msg = (
-                    <FormattedMessage
-                        id='login.verified'
-                        defaultMessage=' Email Verified'
-                    />
-                );
-            }
-
-            if (msg != null) {
                 extraBox = (
                     <div className='alert alert-success'>
                         <i className='fa fa-check'/>
-                        {msg}
+                        <FormattedMessage
+                            id='login.verified'
+                            defaultMessage=' Email Verified'
+                        />
+                    </div>
+                );
+            } else if (extraParam === Constants.SESSION_EXPIRED) {
+                extraBox = (
+                    <div className='alert alert-warning'>
+                        <i className='fa fa-exclamation-triangle'/>
+                        <FormattedMessage
+                            id='login.session_expired'
+                            defaultMessage=' Your session has expired. Please login again.'
+                        />
                     </div>
                 );
             }
@@ -91,7 +127,7 @@ export default class Login extends React.Component {
         if (global.window.mm_config.EnableSignInWithEmail === 'true') {
             emailSignup = (
                 <LoginEmail
-                    teamName={this.props.teamName}
+                    teamName={teamName}
                 />
             );
         }
@@ -125,7 +161,7 @@ export default class Login extends React.Component {
         }
 
         let userSignUp = null;
-        if (this.props.inviteId) {
+        if (currentTeam.allow_open_invite) {
             userSignUp = (
                 <div>
                     <span>
@@ -134,7 +170,7 @@ export default class Login extends React.Component {
                             defaultMessage="Don't have an account? "
                         />
                         <a
-                            href={'/signup_user_complete/?id=' + this.props.inviteId}
+                            href={'/signup_user_complete/?id=' + currentTeam.invite_id}
                             className='signup-team-login'
                         >
                             <FormattedMessage
@@ -168,73 +204,65 @@ export default class Login extends React.Component {
         if (global.window.mm_config.EnableLdap === 'true') {
             ldapLogin = (
                 <LoginLdap
-                    teamName={this.props.teamName}
+                    teamName={teamName}
                 />
             );
         }
 
-        let findTeams = null;
-        if (!Utils.isMobileApp()) {
-            findTeams = (
-                <div className='form-group margin--extra form-group--small'>
-                    <span>
-                        <a href='/find_team'>
-                            <FormattedMessage
-                                id='login.find'
-                                defaultMessage='Find your other teams'
-                            />
-                        </a></span>
-                </div>
-            );
-        }
-
         let usernameLogin = null;
         if (global.window.mm_config.EnableSignInWithUsername === 'true') {
             usernameLogin = (
                 <LoginUsername
-                    teamName={this.props.teamName}
+                    teamName={teamName}
                 />
             );
         }
 
         return (
-            <div className='signup-team__container'>
-                <h5 className='margin--less'>
-                    <FormattedMessage
-                        id='login.signTo'
-                        defaultMessage='Sign in to:'
-                    />
-                </h5>
-                <h2 className='signup-team__name'>{teamDisplayName}</h2>
-                <h2 className='signup-team__subdomain'>
-                    <FormattedMessage
-                        id='login.on'
-                        defaultMessage='on {siteName}'
-                        values={{
-                            siteName: global.window.mm_config.SiteName
-                        }}
-                    />
-                </h2>
-                    {extraBox}
-                    {loginMessage}
-                    {emailSignup}
-                    {usernameLogin}
-                    {ldapLogin}
-                    {userSignUp}
-                    {findTeams}
-                    {forgotPassword}
-                    {teamSignUp}
+            <div>
+                <div className='signup-header'>
+                    <a href='/'>
+                        <span className='fa fa-chevron-left'/>
+                        <FormattedMessage
+                            id='web.header.back'
+                        />
+                    </a>
+                </div>
+                <div className='col-sm-12'>
+                    <div className='signup-team__container'>
+                        <h5 className='margin--less'>
+                            <FormattedMessage
+                                id='login.signTo'
+                                defaultMessage='Sign in to:'
+                            />
+                        </h5>
+                        <h2 className='signup-team__name'>{teamDisplayName}</h2>
+                        <h2 className='signup-team__subdomain'>
+                            <FormattedMessage
+                                id='login.on'
+                                defaultMessage='on {siteName}'
+                                values={{
+                                    siteName: global.window.mm_config.SiteName
+                                }}
+                            />
+                        </h2>
+                        {extraBox}
+                        {loginMessage}
+                        {emailSignup}
+                        {usernameLogin}
+                        {ldapLogin}
+                        {userSignUp}
+                        {forgotPassword}
+                        {teamSignUp}
+                    </div>
+                </div>
             </div>
         );
     }
 }
 
 Login.defaultProps = {
-    teamName: '',
-    teamDisplayName: ''
 };
 Login.propTypes = {
-    teamName: React.PropTypes.string,
-    teamDisplayName: React.PropTypes.string,
-    inviteId: React.PropTypes.string
+    params: React.PropTypes.object.isRequired
 };
-- 
cgit v1.2.3-1-g7c22

