Catch register errors and handle it in front

This commit is contained in:
cyril lopez 2017-12-06 12:19:43 +01:00
parent ec09ee6a28
commit 1084e88826
12 changed files with 26 additions and 13 deletions

View File

@ -67,8 +67,7 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
}
if (!this.isUrlProtected(props) && includes(props.location.pathname, 'register') && this.hasAdminUser(props)) {
// TODO: uncomment
// this.props.history.push('/plugins/users-permissions/auth/login');
this.props.history.push('/plugins/users-permissions/auth/login');
}
if (!props.hasUserPlugin || auth.getToken() && !this.state.hasAlreadyRegistereOtherPlugins) {

View File

@ -55,4 +55,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}

View File

@ -49,7 +49,8 @@
"Content-Type",
"Authorization",
"X-Frame-Options",
"Origin"
"Origin",
"X-Forwarded-Host"
]
},
"ip": {

View File

@ -50,7 +50,8 @@
"headers": [
"Content-Type",
"Authorization",
"X-Frame-Options"
"X-Frame-Options",
"X-Forwarded-Host"
]
},
"ip": {

View File

@ -48,7 +48,8 @@
"headers": [
"Content-Type",
"Authorization",
"X-Frame-Options"
"X-Frame-Options",
"X-Forwarded-Host"
]
},
"ip": {

View File

@ -46,4 +46,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -1,4 +1,4 @@
import { set } from 'lodash';
import { get, includes, set } from 'lodash';
import { call, fork, takeLatest, put, select } from 'redux-saga/effects';
import auth from 'utils/auth';
import request from 'utils/request';
@ -40,7 +40,6 @@ export function* submitForm() {
yield put(submitSucceeded());
} catch(error) {
console.log(error.response.payload);
const formType = yield select(makeSelectFormType());
const errors = error.response.payload.message.reduce((acc, key) => {
@ -67,6 +66,11 @@ export function* submitForm() {
case 'reset-password':
formErrors = [{ name: 'password', errors: [{ id: 'users-permissions.Auth.form.error.password.matching' }] }];
break;
case 'register': {
const target = includes(get(errors, ['0', 'id']), 'username') ? 'username' : 'email';
formErrors = [{ name: target, errors }];
break;
}
default:
}

View File

@ -41,6 +41,8 @@
"Auth.form.error.code.provide": "Incorrect code provided.",
"Auth.form.error.password.matching": "Passwords do not match.",
"Auth.form.error.params.provide": "Incorrect params provided.",
"Auth.form.error.username.taken": "Username is already taken",
"Auth.form.error.email.taken": "Email is already taken",
"Auth.link.forgot-password": "Forgot your password?",
"Auth.link.ready": "Ready to sign-in?",

View File

@ -40,6 +40,8 @@
"Auth.form.error.code.provide": "Le code est incorrect.",
"Auth.form.error.password.matching": "Les mots de passe ne sont pas identique.",
"Auth.form.error.params.provide": "Les informations nos incorrect.",
"Auth.form.error.username.taken": "Ce nom est déjà utilisé",
"Auth.form.error.email.taken": "Cet email est déjà utilisé",
"Auth.link.forgot-password": "Mot de passe oublié?",
"Auth.link.ready": "Prêt à vous connecter?",

View File

@ -49,7 +49,10 @@ module.exports = {
}
return acc;
}, {}));
}, {}))
.catch((err) => {
throw err.detail;
});
},
update: async function (params) {

View File

@ -30,7 +30,7 @@ module.exports = {
return acc;
}, {}))
.catch((error) => {
throw [{ messages: [{ id: error.message }]}];
throw error.message;
});
},

View File

@ -105,10 +105,10 @@ module.exports = {
});
} catch(err) {
const adminError = _.includes(err, 'username') ? 'Auth.form.error.username.taken' : 'Auth.form.error.email.taken';
ctx.badRequest(null, err)
ctx.badRequest(null, ctx.request.admin ? [{ messages: [{ id: adminError }] }] : err);
}
},
forgotPassword: async (ctx) => {