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.switchForm = this.switchForm.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); const { hash } = window.location; if (hash === '#register') { this.state.isRegistering = true; } } switchForm() { this.setState({ isRegistering: !this.state.isRegistering }); } renderLocalOrLdapLoginForm() { const { t, csrf, isLdapStrategySetup } = this.props; return (
{isLdapStrategySetup && (
LDAP
)}
{/* [TODO][GW-2112] An AppContainer gets csrf data */}
); } renderExternalAuthInput(auth) { const { t, csrf } = this.props; return (
{/* [TODO][GW-2112] use onClick, and delete form tag */}
{/* [TODO][GW-2112] An AppContainer gets csrf data */}
by {auth} Account
); } renderExternalAuthLoginForm() { const { isLocalStrategySetup, isLdapStrategySetup, objOfIsExternalAuthEnableds } = this.props; const isExternalAuthCollapsible = isLocalStrategySetup || isLdapStrategySetup; const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : ''; return ( <>
{Object.keys(objOfIsExternalAuthEnableds).map((auth) => { if (!objOfIsExternalAuthEnableds[auth]) { return; } return this.renderExternalAuthInput(auth); })}
); } renderRegisterForm() { const { t, csrf, registrationMode, registrationWhiteList, } = this.props; return (
{registrationMode === 'Restricted' && (

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

)}

{registrationWhiteList.length > 0 && ( <>

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

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