// 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 (

{'LDAP Settings'}

{'When true, Mattermost allows login using LDAP'}

{'The domain or ip address of LDAP server.'}

{'The port to connect to the LDAP server on. Default is 389.'}

{'The base dn where mattermost should search for users.'}

{'Username of a user with read access to the LDAP server specified.'}

{'Password of the user given above.'}

{'The first name attribute of entires in the LDAP server.'}

{'The last name attribute of entries in the LDAP server.'}

{'The email attribute of entries in the LDAP server.'}

{'The attribute of entries in the LDAP server to use for username in Mattermost. May be the same as the ID Attribute.'}

{'The attribute of entries in the LDAP server to use as a unique identifier. Users will use this to login. Ideally this would be the username they are used to loging in with. May be the same as the username attribute above.'}

{'The timeout value for queries to the LDAP server. Increase if you are getting timeout errors caused by a slow LDAP server.'}

{serverError}
); } } LdapSettings.defaultProps = { }; LdapSettings.propTypes = { config: React.PropTypes.object };