import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import loggerFactory from '@alias/logger'; import Modal from 'react-bootstrap/es/Modal'; import { createSubscribedElement } from '../../UnstatedUtils'; import { toastError } from '../../../util/apiNotification'; import AppContainer from '../../../services/AppContainer'; import AdminLdapSecurityContainer from '../../../services/AdminLdapSecurityContainer'; const logger = loggerFactory('growi:security:AdminLdapSecurityContainer'); class LdapAuthTestModal extends React.Component { constructor(props) { super(props); this.state = { username: '', password: '', logs: '', }; this.onChangeUsername = this.onChangeUsername.bind(this); this.onChangePassword = this.onChangePassword.bind(this); this.addLogs = this.addLogs.bind(this); this.testLdapCredentials = this.testLdapCredentials.bind(this); } /** * Change username */ onChangeUsername(username) { this.setState({ username }); } /** * Change password */ onChangePassword(password) { this.setState({ password }); } /** * add logs */ addLogs(log) { const newLog = `${new Date()} - ${log}\n\n`; this.setState({ logs: `${newLog}${this.state.logs}`, }); } /** * Test ldap auth */ async testLdapCredentials() { try { const response = await this.props.appContainer.apiPost('/login/testLdap', { loginForm: { username: this.state.username, password: this.state.password, }, }); // add logs if (response.err) { this.addLogs(response.err); } if (response.ldapConfiguration) { const prettified = JSON.stringify(response.ldapConfiguration.server, undefined, 4); this.addLogs(`LDAP Configuration : ${prettified}`); } if (response.ldapAccountInfo) { const prettified = JSON.stringify(response.ldapAccountInfo, undefined, 4); this.addLogs(`Retrieved LDAP Account : ${prettified}`); } } // Catch server communication error catch (err) { toastError(err); logger.error(err); } } render() { const { t } = this.props; return ( Test LDAP Account
{ this.onChangeUsername(e.target.value) }} />
{ this.onChangePassword(e.target.value) }} />
Logs