import React from 'react';
import { useTranslation } from 'next-i18next';
import PropTypes from 'prop-types';
import ReactCardFlip from 'react-card-flip';
import { useCsrfToken } from '~/stores/context';
class LoginForm extends React.Component {
constructor(props) {
super(props);
this.state = {
isRegistering: false,
};
this.switchForm = this.switchForm.bind(this);
this.handleLoginWithExternalAuth = this.handleLoginWithExternalAuth.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 });
}
handleLoginWithExternalAuth(e) {
const auth = e.currentTarget.id;
window.location.href = `/passport/${auth}`;
}
renderLocalOrLdapLoginForm() {
const { t, csrfToken, isLdapStrategySetup } = this.props;
return (
);
}
renderExternalAuthInput(auth) {
const { t } = this.props;
const authIconNames = {
google: 'google',
github: 'github',
facebook: 'facebook',
twitter: 'twitter',
oidc: 'openid',
saml: 'key',
basic: 'lock',
};
return (
by {auth} Account
);
}
renderExternalAuthLoginForm() {
const { isLocalStrategySetup, isLdapStrategySetup, objOfIsExternalAuthEnableds } = this.props;
const isExternalAuthCollapsible = isLocalStrategySetup || isLdapStrategySetup;
const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth' : '';
return (
<>
{Object.keys(objOfIsExternalAuthEnableds).map((auth) => {
if (!objOfIsExternalAuthEnableds[auth]) {
return;
}
return this.renderExternalAuthInput(auth);
})}
>
);
}
renderRegisterForm() {
const {
t,
// appContainer,
csrfToken,
isEmailAuthenticationEnabled,
username,
name,
email,
registrationMode,
registrationWhiteList,
isMailerSetup,
} = this.props;
let registerAction = '/register';
let submitText = t('Sign up');
if (isEmailAuthenticationEnabled) {
registerAction = '/user-activation/register';
submitText = t('page_register.send_email');
}
return (
{registrationMode === 'Restricted' && (
{t('page_register.notice.restricted')}
{t('page_register.notice.restricted_defail')}
)}
{ (!isMailerSetup && isEmailAuthenticationEnabled) && (
{t('security_settings.Local.please_enable_mailer')}
)}
);
}
render() {
const {
t,
isLocalStrategySetup,
isLdapStrategySetup,
isRegistrationEnabled,
isPasswordResetEnabled,
objOfIsExternalAuthEnableds,
} = this.props;
const isLocalOrLdapStrategiesEnabled = isLocalStrategySetup || isLdapStrategySetup;
// const isSomeExternalAuthEnabled = Object.values(objOfIsExternalAuthEnableds).some(elem => elem);
const isSomeExternalAuthEnabled = true;
return (
{isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()}
{isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()}
{isLocalOrLdapStrategiesEnabled && isPasswordResetEnabled && (
)}
{isRegistrationEnabled && (
)}
{isRegistrationEnabled && this.renderRegisterForm()}
GROWI.ORG
);
}
}
LoginForm.propTypes = {
// i18next
t: PropTypes.func.isRequired,
// appContainer: PropTypes.instanceOf(AppContainer).isRequired,
csrfToken: PropTypes.string,
isRegistering: PropTypes.bool,
username: PropTypes.string,
name: PropTypes.string,
email: PropTypes.string,
isRegistrationEnabled: PropTypes.bool,
registrationMode: PropTypes.string,
registrationWhiteList: PropTypes.array,
isPasswordResetEnabled: PropTypes.bool,
isEmailAuthenticationEnabled: PropTypes.bool,
isLocalStrategySetup: PropTypes.bool,
isLdapStrategySetup: PropTypes.bool,
objOfIsExternalAuthEnableds: PropTypes.object,
isMailerSetup: PropTypes.bool,
};
const LoginFormWrapperFC = (props) => {
const { t } = useTranslation();
const { data: csrfToken } = useCsrfToken();
return ;
};
/**
* Wrapper component for using unstated
*/
// const LoginFormWrapper = withUnstatedContainers(LoginFormWrapperFC, [AppContainer]);
// export default LoginForm;
export default LoginFormWrapperFC;