From 58358ddd7cd0152bf16a7326e1d595524fb51246 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Tue, 8 Dec 2015 13:38:43 -0500
Subject: Some refactoring

---
 web/react/components/login_ldap.jsx | 110 ++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 web/react/components/login_ldap.jsx

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

diff --git a/web/react/components/login_ldap.jsx b/web/react/components/login_ldap.jsx
new file mode 100644
index 000000000..1e0e32f4f
--- /dev/null
+++ b/web/react/components/login_ldap.jsx
@@ -0,0 +1,110 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import * as Utils from '../utils/utils.jsx';
+import * as Client from '../utils/client.jsx';
+
+export default class LoginLdap extends React.Component {
+    constructor(props) {
+        super(props);
+
+        this.handleSubmit = this.handleSubmit.bind(this);
+
+        this.state = {
+            serverError: ''
+        };
+    }
+    handleSubmit(e) {
+        e.preventDefault();
+        var state = {};
+
+        const teamName = this.props.teamName;
+        if (!teamName) {
+            state.serverError = 'Bad team name';
+            this.setState(state);
+            return;
+        }
+
+        const id = this.refs.id.value.trim();
+        if (!id) {
+            state.serverError = 'An LDAP ID is required';
+            this.setState(state);
+            return;
+        }
+
+        const password = this.refs.password.value.trim();
+        if (!password) {
+            state.serverError = 'An LDAP password is required';
+            this.setState(state);
+            return;
+        }
+
+        state.serverError = '';
+        this.setState(state);
+
+        Client.loginByLdap(teamName, id, password,
+            () => {
+                const redirect = Utils.getUrlParameter('redirect');
+                if (redirect) {
+                    window.location.href = decodeURIComponent(redirect);
+                } else {
+                    window.location.href = '/' + teamName + '/channels/town-square';
+                }
+            },
+            (err) => {
+                state.serverError = err.message;
+                this.setState(state);
+            }
+        );
+    }
+    render() {
+        let serverError;
+        let errorClass = '';
+        if (this.state.serverError) {
+            serverError = <label className='control-label'>{this.state.serverError}</label>;
+            errorClass = ' has-error';
+        }
+
+        return (
+            <form onSubmit={this.handleSubmit}>
+                <div className='signup__email-container'>
+                    <div className={'form-group' + errorClass}>
+                        {serverError}
+                    </div>
+                    <div className={'form-group' + errorClass}>
+                        <input
+                            autoFocus={true}
+                            className='form-control'
+                            ref='id'
+                            placeholder='LDAP Username'
+                            spellCheck='false'
+                        />
+                    </div>
+                    <div className={'form-group' + errorClass}>
+                        <input
+                            type='password'
+                            className='form-control'
+                            ref='password'
+                            placeholder='LDAP Password'
+                            spellCheck='false'
+                        />
+                    </div>
+                    <div className='form-group'>
+                        <button
+                            type='submit'
+                            className='btn btn-primary'
+                        >
+                            {'Sign in'}
+                        </button>
+                    </div>
+                </div>
+            </form>
+        );
+    }
+}
+LoginLdap.defaultProps = {
+};
+
+LoginLdap.propTypes = {
+    teamName: React.PropTypes.string.isRequired
+};
-- 
cgit v1.2.3-1-g7c22

