mirror of
https://github.com/strapi/strapi.git
synced 2025-07-24 09:25:25 +00:00
Prevent user from going to login page id no user is registered
This commit is contained in:
parent
455ff3ed68
commit
02e2016a7a
@ -66,10 +66,22 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
|
||||
this.props.history.push(`/plugins/users-permissions/auth/${endPoint}`);
|
||||
}
|
||||
|
||||
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'register') && this.hasAdminUser(props)) {
|
||||
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'auth/register') && this.hasAdminUser(props)) {
|
||||
this.props.history.push('/plugins/users-permissions/auth/login');
|
||||
}
|
||||
|
||||
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'auth/login') && !this.hasAdminUser(props)) {
|
||||
this.props.history.push('/plugins/users-permissions/auth/register');
|
||||
}
|
||||
|
||||
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'auth/forgot-password') && !this.hasAdminUser(props)) {
|
||||
this.props.history.push('/plugins/users-permissions/auth/register');
|
||||
}
|
||||
|
||||
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'auth/reset-password') && !this.hasAdminUser(props)) {
|
||||
this.props.history.push('/plugins/users-permissions/auth/register');
|
||||
}
|
||||
|
||||
if (!props.hasUserPlugin || auth.getToken() && !this.state.hasAlreadyRegistereOtherPlugins) {
|
||||
map(omit(this.props.plugins.toJS(), ['users-permissions', 'email']), plugin => {
|
||||
switch (true) {
|
||||
|
@ -77,9 +77,10 @@ export function setForm(formType, email) {
|
||||
};
|
||||
}
|
||||
|
||||
export function submit() {
|
||||
export function submit(context) {
|
||||
return {
|
||||
type: SUBMIT,
|
||||
context,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ export class AuthPage extends React.Component { // eslint-disable-line react/pre
|
||||
this.props.setErrors(formErrors);
|
||||
|
||||
if (isEmpty(formErrors)) {
|
||||
this.props.submit();
|
||||
this.props.submit(this.context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,6 +190,10 @@ export class AuthPage extends React.Component { // eslint-disable-line react/pre
|
||||
}
|
||||
}
|
||||
|
||||
AuthPage.contextTypes = {
|
||||
updatePlugin: PropTypes.func,
|
||||
};
|
||||
|
||||
AuthPage.propTypes = {
|
||||
didCheckErrors: PropTypes.bool.isRequired,
|
||||
formErrors: PropTypes.array.isRequired,
|
||||
|
@ -7,7 +7,7 @@ import { makeSelectFormType, makeSelectModifiedData } from './selectors';
|
||||
import { submitError, submitSucceeded } from './actions';
|
||||
import { SUBMIT } from './constants';
|
||||
|
||||
export function* submitForm() {
|
||||
export function* submitForm(action) {
|
||||
try {
|
||||
const formType = yield select(makeSelectFormType());
|
||||
const body = yield select(makeSelectModifiedData());
|
||||
@ -38,11 +38,15 @@ export function* submitForm() {
|
||||
yield call(auth.setUserInfo, response.user, body.rememberMe);
|
||||
}
|
||||
|
||||
if (formType === 'register') {
|
||||
action.context.updatePlugin('users-permissions', 'hasAdminUser', true);
|
||||
}
|
||||
|
||||
yield put(submitSucceeded());
|
||||
} catch(error) {
|
||||
const formType = yield select(makeSelectFormType());
|
||||
|
||||
if (isArray(error.response.payload.message)) {
|
||||
if (isArray(get(error, ['response', 'payload', 'message']))) {
|
||||
|
||||
const errors = error.response.payload.message.reduce((acc, key) => {
|
||||
const err = key.messages.reduce((acc, key) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user