// 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 = ; errorClass = ' has-error'; } return (
{serverError}
); } } LoginLdap.defaultProps = { }; LoginLdap.propTypes = { teamName: React.PropTypes.string.isRequired };