|
@@ -3,55 +3,43 @@ import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { withTranslation } from 'react-i18next';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
+import { createSubscribedElement } from './UnstatedUtils';
|
|
|
|
|
+import AppContainer from '../services/AppContainer';
|
|
|
|
|
+
|
|
|
class LoginForm extends React.Component {
|
|
class LoginForm extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
|
|
- this.isRegistrationEnabled = false;
|
|
|
|
|
- this.registrationMode = 'Closed';
|
|
|
|
|
- this.registrationWhiteList = [];
|
|
|
|
|
- this.isLocalStrategySetup = false;
|
|
|
|
|
- this.isLdapStrategySetup = false;
|
|
|
|
|
- this.objOfIsExternalAuthEnableds = {};
|
|
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ isRegistering: false,
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
this.switchForm = this.switchForm.bind(this);
|
|
this.switchForm = this.switchForm.bind(this);
|
|
|
|
|
+ this.handleLoginWithExternalAuth = this.handleLoginWithExternalAuth.bind(this);
|
|
|
this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this);
|
|
this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this);
|
|
|
this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this);
|
|
this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this);
|
|
|
this.renderExternalAuthInput = this.renderExternalAuthInput.bind(this);
|
|
this.renderExternalAuthInput = this.renderExternalAuthInput.bind(this);
|
|
|
this.renderRegisterForm = this.renderRegisterForm.bind(this);
|
|
this.renderRegisterForm = this.renderRegisterForm.bind(this);
|
|
|
|
|
+
|
|
|
|
|
+ const { hash } = window.location;
|
|
|
|
|
+ if (hash === '#register') {
|
|
|
|
|
+ this.state.isRegistering = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ switchForm() {
|
|
|
|
|
+ this.setState({ isRegistering: !this.state.isRegistering });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // for flip [TODO][GW-1865] use state or react component for flip
|
|
|
|
|
- switchForm(e) {
|
|
|
|
|
- if (e.target.id === 'register') {
|
|
|
|
|
- $('#login-dialog').addClass('to-flip');
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- $('#login-dialog').removeClass('to-flip');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ handleLoginWithExternalAuth(e) {
|
|
|
|
|
+ const auth = e.currentTarget.id;
|
|
|
|
|
+ const csrf = this.props.appContainer.csrfToken;
|
|
|
|
|
+ window.location.href = `/passport/${auth}?_csrf=${csrf}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderLocalOrLdapLoginForm() {
|
|
renderLocalOrLdapLoginForm() {
|
|
|
- const { t, csrf } = this.props;
|
|
|
|
|
|
|
+ const { t, appContainer, isLdapStrategySetup } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<form role="form" action="/login" method="post">
|
|
<form role="form" action="/login" method="post">
|
|
@@ -62,7 +50,7 @@ class LoginForm extends React.Component {
|
|
|
</span>
|
|
</span>
|
|
|
</div>
|
|
</div>
|
|
|
<input type="text" className="form-control" placeholder="Username or E-mail" name="loginForm[username]" />
|
|
<input type="text" className="form-control" placeholder="Username or E-mail" name="loginForm[username]" />
|
|
|
- {this.isLdapStrategySetup && (
|
|
|
|
|
|
|
+ {isLdapStrategySetup && (
|
|
|
<div className="input-group-append">
|
|
<div className="input-group-append">
|
|
|
<small className="input-group-text text-success">
|
|
<small className="input-group-text text-success">
|
|
|
<i className="icon-fw icon-check"></i> LDAP
|
|
<i className="icon-fw icon-check"></i> LDAP
|
|
@@ -81,8 +69,7 @@ class LoginForm extends React.Component {
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div className="input-group mt-5">
|
|
<div className="input-group mt-5">
|
|
|
- {/* [TODO][GW-1913] An AppContainer gets csrf data */}
|
|
|
|
|
- <input type="hidden" name="_csrf" value={csrf} />
|
|
|
|
|
|
|
+ <input type="hidden" name="_csrf" value={appContainer.csrfToken} />
|
|
|
<button type="submit" id="login" className="btn btn-fill login mx-auto">
|
|
<button type="submit" id="login" className="btn btn-fill login mx-auto">
|
|
|
<div className="eff"></div>
|
|
<div className="eff"></div>
|
|
|
<span className="btn-label">
|
|
<span className="btn-label">
|
|
@@ -96,7 +83,7 @@ class LoginForm extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderExternalAuthInput(auth) {
|
|
renderExternalAuthInput(auth) {
|
|
|
- const { t, csrf } = this.props;
|
|
|
|
|
|
|
+ const { t } = this.props;
|
|
|
const authIconNames = {
|
|
const authIconNames = {
|
|
|
google: 'google',
|
|
google: 'google',
|
|
|
github: 'github',
|
|
github: 'github',
|
|
@@ -108,26 +95,22 @@ class LoginForm extends React.Component {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="col-6">
|
|
|
|
|
- {/* [TODO][GW-1913] use onClick, and delete form tag */}
|
|
|
|
|
- <form key={auth} role="form" action={`/passport/${auth}`} className="mb-2">
|
|
|
|
|
- {/* [TODO][GW-1913] An AppContainer gets csrf data */}
|
|
|
|
|
- <input type="hidden" name="_csrf" value={csrf} />
|
|
|
|
|
- <button type="submit" className="btn btn-fill" id={auth}>
|
|
|
|
|
- <div className="eff"></div>
|
|
|
|
|
- <span className="btn-label">
|
|
|
|
|
- <i className={`fa fa-${authIconNames[auth]}`}></i>
|
|
|
|
|
- </span>
|
|
|
|
|
- <span className="btn-label-text">{t('Sign in')}</span>
|
|
|
|
|
- </button>
|
|
|
|
|
- <div className="small text-right">by {auth} Account</div>
|
|
|
|
|
- </form>
|
|
|
|
|
|
|
+ <div key={auth} className="col-6 mb-2">
|
|
|
|
|
+ <button type="button" className="btn btn-fill" id={auth} onClick={this.handleLoginWithExternalAuth}>
|
|
|
|
|
+ <div className="eff"></div>
|
|
|
|
|
+ <span className="btn-label">
|
|
|
|
|
+ <i className={`fa fa-${authIconNames[auth]}`}></i>
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="btn-label-text">{t('Sign in')}</span>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <div className="small text-right">by {auth} Account</div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderExternalAuthLoginForm() {
|
|
renderExternalAuthLoginForm() {
|
|
|
- const isExternalAuthCollapsible = this.isLocalStrategySetup || this.isLdapStrategySetup;
|
|
|
|
|
|
|
+ const { isLocalStrategySetup, isLdapStrategySetup, objOfIsExternalAuthEnableds } = this.props;
|
|
|
|
|
+ const isExternalAuthCollapsible = isLocalStrategySetup || isLdapStrategySetup;
|
|
|
const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : '';
|
|
const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : '';
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -135,8 +118,8 @@ class LoginForm extends React.Component {
|
|
|
<div className="border-top border-bottom">
|
|
<div className="border-top border-bottom">
|
|
|
<div id="external-auth" className={`external-auth ${collapsibleClass}`}>
|
|
<div id="external-auth" className={`external-auth ${collapsibleClass}`}>
|
|
|
<div className="row mt-2">
|
|
<div className="row mt-2">
|
|
|
- {Object.keys(this.objOfIsExternalAuthEnableds).map(auth => {
|
|
|
|
|
- if (!this.objOfIsExternalAuthEnableds[auth]) {
|
|
|
|
|
|
|
+ {Object.keys(objOfIsExternalAuthEnableds).map((auth) => {
|
|
|
|
|
+ if (!objOfIsExternalAuthEnableds[auth]) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
return this.renderExternalAuthInput(auth);
|
|
return this.renderExternalAuthInput(auth);
|
|
@@ -161,10 +144,19 @@ class LoginForm extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
renderRegisterForm() {
|
|
renderRegisterForm() {
|
|
|
- const { t, csrf } = this.props;
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ t,
|
|
|
|
|
+ username,
|
|
|
|
|
+ name,
|
|
|
|
|
+ email,
|
|
|
|
|
+ appContainer,
|
|
|
|
|
+ registrationMode,
|
|
|
|
|
+ registrationWhiteList,
|
|
|
|
|
+ } = this.props;
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="back">
|
|
<div className="back">
|
|
|
- {this.registrationMode === 'Restricted' && (
|
|
|
|
|
|
|
+ {registrationMode === 'Restricted' && (
|
|
|
<p className="alert alert-warning">
|
|
<p className="alert alert-warning">
|
|
|
{t('page_register.notice.restricted')}
|
|
{t('page_register.notice.restricted')}
|
|
|
<br />
|
|
<br />
|
|
@@ -178,7 +170,7 @@ class LoginForm extends React.Component {
|
|
|
<i className="icon-user"></i>
|
|
<i className="icon-user"></i>
|
|
|
</span>
|
|
</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <input type="text" className="form-control" placeholder={t('User ID')} name="registerForm[username]" defaultValue={this.props.username} required />
|
|
|
|
|
|
|
+ <input type="text" className="form-control" placeholder={t('User ID')} name="registerForm[username]" defaultValue={username} required />
|
|
|
</div>
|
|
</div>
|
|
|
<p className="form-text text-danger">
|
|
<p className="form-text text-danger">
|
|
|
<span id="help-block-username"></span>
|
|
<span id="help-block-username"></span>
|
|
@@ -190,7 +182,7 @@ class LoginForm extends React.Component {
|
|
|
<i className="icon-tag"></i>
|
|
<i className="icon-tag"></i>
|
|
|
</span>
|
|
</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <input type="text" className="form-control" placeholder={t('Name')} name="registerForm[name]" defaultValue={this.props.name} required />
|
|
|
|
|
|
|
+ <input type="text" className="form-control" placeholder={t('Name')} name="registerForm[name]" defaultValue={name} required />
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div className="input-group">
|
|
<div className="input-group">
|
|
@@ -199,17 +191,17 @@ class LoginForm extends React.Component {
|
|
|
<i className="icon-envelope"></i>
|
|
<i className="icon-envelope"></i>
|
|
|
</span>
|
|
</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <input type="email" className="form-control" placeholder={t('Email')} name="registerForm[email]" defaultValue={this.props.email} required />
|
|
|
|
|
|
|
+ <input type="email" className="form-control" placeholder={t('Email')} name="registerForm[email]" defaultValue={email} required />
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- {this.registrationWhiteList.length > 0 && (
|
|
|
|
|
|
|
+ {registrationWhiteList.length > 0 && (
|
|
|
<>
|
|
<>
|
|
|
<p className="form-text">{t('page_register.form_help.email')}</p>
|
|
<p className="form-text">{t('page_register.form_help.email')}</p>
|
|
|
<ul>
|
|
<ul>
|
|
|
- {this.registrationWhiteList.map((elem) => {
|
|
|
|
|
|
|
+ {registrationWhiteList.map((elem) => {
|
|
|
return (
|
|
return (
|
|
|
- <li>
|
|
|
|
|
- <code>{{ elem }}</code>
|
|
|
|
|
|
|
+ <li key={elem}>
|
|
|
|
|
+ <code>{elem}</code>
|
|
|
</li>
|
|
</li>
|
|
|
);
|
|
);
|
|
|
})}
|
|
})}
|
|
@@ -227,8 +219,7 @@ class LoginForm extends React.Component {
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div className="input-group justify-content-center mt-5">
|
|
<div className="input-group justify-content-center mt-5">
|
|
|
- {/* [TODO][GW-1913] An AppContainer gets csrf data */}
|
|
|
|
|
- <input type="hidden" name="_csrf" value={csrf} />
|
|
|
|
|
|
|
+ <input type="hidden" name="_csrf" value={appContainer.csrfToken} />
|
|
|
<button type="submit" className="btn btn-fill" id="register">
|
|
<button type="submit" className="btn btn-fill" id="register">
|
|
|
<div className="eff"></div>
|
|
<div className="eff"></div>
|
|
|
<span className="btn-label">
|
|
<span className="btn-label">
|
|
@@ -243,7 +234,7 @@ class LoginForm extends React.Component {
|
|
|
|
|
|
|
|
<div className="row">
|
|
<div className="row">
|
|
|
<div className="text-right col-12 py-1">
|
|
<div className="text-right col-12 py-1">
|
|
|
- <a href="#login" id="login" className="link-switch" onClick={this.handleClick}>
|
|
|
|
|
|
|
+ <a href="#login" id="login" className="link-switch" onClick={this.switchForm}>
|
|
|
<i className="icon-fw icon-login"></i>
|
|
<i className="icon-fw icon-login"></i>
|
|
|
{t('Sign in is here')}
|
|
{t('Sign in is here')}
|
|
|
</a>
|
|
</a>
|
|
@@ -254,11 +245,17 @@ class LoginForm extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { t, isRegistering } = this.props;
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ t,
|
|
|
|
|
+ isLocalStrategySetup,
|
|
|
|
|
+ isLdapStrategySetup,
|
|
|
|
|
+ isRegistrationEnabled,
|
|
|
|
|
+ objOfIsExternalAuthEnableds,
|
|
|
|
|
+ } = this.props;
|
|
|
|
|
|
|
|
- const isLocalOrLdapStrategiesEnabled = this.isLocalStrategySetup || this.isLdapStrategySetup;
|
|
|
|
|
- const registerFormClass = isRegistering ? 'to-flip' : '';
|
|
|
|
|
- const isSomeExternalAuthEnabled = Object.values(this.objOfIsExternalAuthEnableds).some(elem => elem);
|
|
|
|
|
|
|
+ const isLocalOrLdapStrategiesEnabled = isLocalStrategySetup || isLdapStrategySetup;
|
|
|
|
|
+ const registerFormClass = this.state.isRegistering ? 'to-flip' : '';
|
|
|
|
|
+ const isSomeExternalAuthEnabled = Object.values(objOfIsExternalAuthEnableds).some(elem => elem);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className={`login-dialog mx-auto flipper ${registerFormClass}`} id="login-dialog">
|
|
<div className={`login-dialog mx-auto flipper ${registerFormClass}`} id="login-dialog">
|
|
@@ -267,7 +264,7 @@ class LoginForm extends React.Component {
|
|
|
<div className="front">
|
|
<div className="front">
|
|
|
{isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()}
|
|
{isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()}
|
|
|
{isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()}
|
|
{isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()}
|
|
|
- {this.isRegistrationEnabled && (
|
|
|
|
|
|
|
+ {isRegistrationEnabled && (
|
|
|
<div className="row">
|
|
<div className="row">
|
|
|
<div className="col-12 text-right py-2">
|
|
<div className="col-12 text-right py-2">
|
|
|
<a href="#register" id="register" className="link-switch" onClick={this.switchForm}>
|
|
<a href="#register" id="register" className="link-switch" onClick={this.switchForm}>
|
|
@@ -277,7 +274,7 @@ class LoginForm extends React.Component {
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|
|
|
- {this.isRegistrationEnabled && this.renderRegisterForm()}
|
|
|
|
|
|
|
+ {isRegistrationEnabled && this.renderRegisterForm()}
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<a href="https://growi.org" className="link-growi-org pl-3">
|
|
<a href="https://growi.org" className="link-growi-org pl-3">
|
|
@@ -289,14 +286,27 @@ class LoginForm extends React.Component {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Wrapper component for using unstated
|
|
|
|
|
+ */
|
|
|
|
|
+const LoginFormWrapper = (props) => {
|
|
|
|
|
+ return createSubscribedElement(LoginForm, props, [AppContainer]);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
LoginForm.propTypes = {
|
|
LoginForm.propTypes = {
|
|
|
// i18next
|
|
// i18next
|
|
|
t: PropTypes.func.isRequired,
|
|
t: PropTypes.func.isRequired,
|
|
|
|
|
+ appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
isRegistering: PropTypes.bool,
|
|
isRegistering: PropTypes.bool,
|
|
|
username: PropTypes.string,
|
|
username: PropTypes.string,
|
|
|
name: PropTypes.string,
|
|
name: PropTypes.string,
|
|
|
email: 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);
|
|
|
|
|
|
|
+export default withTranslation()(LoginFormWrapper);
|