// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Client from '../../utils/client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; const DEFAULT_LDAP_PORT = 389; const DEFAULT_QUERY_TIMEOUT = 60; export default class LdapSettings extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleChange = this.handleChange.bind(this); this.handleEnable = this.handleEnable.bind(this); this.handleDisable = this.handleDisable.bind(this); this.state = { saveNeeded: false, serverError: null, enable: this.props.config.LdapSettings.Enable }; } handleChange() { this.setState({saveNeeded: true}); } handleEnable() { this.setState({saveNeeded: true, enable: true}); } handleDisable() { this.setState({saveNeeded: true, enable: false}); } handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); const config = this.props.config; config.LdapSettings.Enable = this.refs.Enable.checked; config.LdapSettings.LdapServer = this.refs.LdapServer.value.trim(); let LdapPort = DEFAULT_LDAP_PORT; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.LdapPort).value, 10))) { LdapPort = parseInt(ReactDOM.findDOMNode(this.refs.LdapPort).value, 10); } config.LdapSettings.LdapPort = LdapPort; config.LdapSettings.BaseDN = this.refs.BaseDN.value.trim(); config.LdapSettings.BindUsername = this.refs.BindUsername.value.trim(); config.LdapSettings.BindPassword = this.refs.BindPassword.value.trim(); config.LdapSettings.FirstNameAttribute = this.refs.FirstNameAttribute.value.trim(); config.LdapSettings.LastNameAttribute = this.refs.LastNameAttribute.value.trim(); config.LdapSettings.EmailAttribute = this.refs.EmailAttribute.value.trim(); config.LdapSettings.UsernameAttribute = this.refs.UsernameAttribute.value.trim(); config.LdapSettings.IdAttribute = this.refs.IdAttribute.value.trim(); let QueryTimeout = DEFAULT_QUERY_TIMEOUT; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.QueryTimeout).value, 10))) { QueryTimeout = parseInt(ReactDOM.findDOMNode(this.refs.QueryTimeout).value, 10); } config.LdapSettings.QueryTimeout = QueryTimeout; Client.saveConfig( config, () => { AsyncClient.getConfig(); this.setState({ serverError: null, saveNeeded: false }); $('#save-button').button('reset'); }, (err) => { this.setState({ serverError: err.message, saveNeeded: true }); $('#save-button').button('reset'); } ); } render() { let serverError = ''; if (this.state.serverError) { serverError =
; } let saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } return ({'If a user attribute changes on the LDAP server it will be updated the next time the user enters their credentials to log in to Mattermost. This includes if a user is made inactive or removed from an LDAP server. Synchronization with LDAP servers is planned in a future release.'}