// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as Client from 'utils/client.jsx'; import * as Utils from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import ConnectionSecurityDropdownSetting from './connection_security_dropdown_setting.jsx'; import BooleanSetting from './boolean_setting.jsx'; const DEFAULT_LDAP_PORT = 389; const DEFAULT_QUERY_TIMEOUT = 60; import React from 'react'; 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, connectionSecurity: this.props.config.LdapSettings.ConnectionSecurity, skipCertificateVerification: this.props.config.LdapSettings.SkipCertificateVerification }; } 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(); config.LdapSettings.UserFilter = this.refs.UserFilter.value.trim(); config.LdapSettings.ConnectionSecurity = this.state.connectionSecurity.trim(); config.LdapSettings.SkipCertificateVerification = this.state.skipCertificateVerification; config.LdapSettings.LoginFieldName = this.refs.LoginFieldName.value.trim(); config.LdapSettings.PasswordFieldName = this.refs.PasswordFieldName.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'; } const licenseEnabled = global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.LDAP === 'true'; let bannerContent; if (licenseEnabled) { bannerContent = (

); } else { bannerContent = (
); } return (
{bannerContent}

this.setState({connectionSecurity: e.target.value, saveNeeded: true})} isDisabled={!this.state.enable} />

} currentValue={this.state.skipCertificateVerification} isDisabled={!this.state.enable} handleChange={(e) => this.setState({skipCertificateVerification: e.target.value.trim() === 'true', saveNeeded: true})} helpText={

} />

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