import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; class LoginForm extends React.Component { constructor(props) { super(props); this.state = { isRegistering: false, }; this.isRegistrationEnabled = false; this.registrationMode = 'Closed'; this.registrationWhiteList = []; this.isLocalStrategySetup = false; this.isLdapStrategySetup = false; this.objOfIsExternalAuthEnableds = {}; this.onClickSwitchFormBtn = this.onClickSwitchFormBtn.bind(this); this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this); this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this); this.renderExternalAuthInput = this.renderExternalAuthInput.bind(this); this.renderRegisterForm = this.renderRegisterForm.bind(this); } componentWillMount() { // [TODO][GW-1913] get params from server with axios this.isRegistrationEnabled = true; this.registrationMode = 'Open'; this.registrationWhiteList = []; this.isLocalStrategySetup = true; this.isLdapStrategySetup = true; this.objOfIsExternalAuthEnableds = { google: true, github: true, facebook: true, twitter: true, oidc: true, saml: true, basic: true, }; } componentDidMount() { const { hash } = window.location; if (hash === '#register') { this.setState({ isRegistering: true }); } } onClickSwitchFormBtn() { this.setState({ isRegistering: !this.state.isRegistering }); } renderLocalOrLdapLoginForm() { const { t, csrf } = this.props; return (
{this.isLdapStrategySetup && (
LDAP
)}
{/* [TODO][GW-1913] An AppContainer gets csrf data */}
); } renderExternalAuthInput(auth) { const { t, csrf } = this.props; return (
{/* [TODO][GW-1913] use onClick, and delete form tag */}
{/* [TODO][GW-1913] An AppContainer gets csrf data */}
by {auth} Account
); } renderExternalAuthLoginForm() { const isExternalAuthCollapsible = this.isLocalStrategySetup || this.isLdapStrategySetup; const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : ''; return ( <>
{Object.keys(this.objOfIsExternalAuthEnableds).map((auth) => { if (!this.objOfIsExternalAuthEnableds[auth]) { return; } return this.renderExternalAuthInput(auth); })}
); } renderRegisterForm() { const { t, csrf } = this.props; return (
{this.registrationMode === 'Restricted' && (

{t('page_register.notice.restricted')}
{t('page_register.notice.restricted_defail')}

)}

{this.registrationWhiteList.length > 0 && ( <>

{t('page_register.form_help.email')}

)}
{/* [TODO][GW-1913] An AppContainer gets csrf data */}
{t('Sign in is here')}
); } render() { const { t } = this.props; const isLocalOrLdapStrategiesEnabled = this.isLocalStrategySetup || this.isLdapStrategySetup; const registerFormClass = this.state.isRegistering ? 'to-flip' : ''; const isSomeExternalAuthEnabled = Object.values(this.objOfIsExternalAuthEnableds).some(elem => elem); return (
{isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()} {isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()} {this.isRegistrationEnabled && (
)}
{this.isRegistrationEnabled && this.renderRegisterForm()} GROWI.ORG
); } } LoginForm.propTypes = { // i18next t: PropTypes.func.isRequired, username: PropTypes.string, name: PropTypes.string, email: PropTypes.string, csrf: PropTypes.string, }; export default withTranslation()(LoginForm);