import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
class LoginForm extends React.Component {
constructor(props) {
super(props);
this.isRegistrationEnabled = false;
this.isLocalStrategySetup = false;
this.isLdapStrategySetup = false;
this.objOfIsExternalAuthEnableds = {};
this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this);
this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this);
this.renderExternalAuthInput = this.renderExternalAuthInput.bind(this);
}
componentWillMount() {
// [TODO][GW-1913] get params from server with axios
this.isRegistrationEnabled = true;
this.isLocalStrategySetup = true;
this.isLdapStrategySetup = true;
this.objOfIsExternalAuthEnableds = {
google: true,
github: true,
facebook: true,
twitter: true,
oidc: true,
saml: true,
basic: true,
};
}
renderLocalOrLdapLoginForm() {
const { t } = this.props;
return (
);
}
renderExternalAuthInput(auth) {
const { t } = this.props;
return (
{/* [TODO][GW-1913] use onClick, and delete form tag */}
);
}
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);
})}
>
);
}
render() {
const { t, isRegistering } = this.props;
const isLocalOrLdapStrategiesEnabled = this.isLocalStrategySetup || this.isLdapStrategySetup;
const registerFormClass = isRegistering ? 'to-flip' : '';
const isSomeExternalAuthEnabled = Object.values(this.objOfIsExternalAuthEnableds).some(elem => elem);
return (
{ isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm() }
{ isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm() }
{/* [TODO][GW-1863] render register form here */}
{this.isRegistrationEnabled && (
)}
);
}
}
LoginForm.propTypes = {
// i18next
t: PropTypes.func.isRequired,
isRegistering: PropTypes.bool,
csrf: PropTypes.string,
};
export default withTranslation()(LoginForm);