local login test

This commit is contained in:
Victor Piousbox
2016-03-21 05:48:37 +00:00
parent 1d3c67af40
commit 5426d63a36
2 changed files with 71 additions and 3 deletions
+2 -3
View File
@@ -180,7 +180,7 @@ function _loginRes (user, req, res) {
api.loginLocal = {
method: 'POST',
url: '/user/auth/local/login',
middlewares: [cron],
middlewares: [],
async handler (req, res) {
req.checkBody({
username: {
@@ -192,7 +192,6 @@ api.loginLocal = {
errorMessage: res.t('missingPassword'),
},
});
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
@@ -211,7 +210,7 @@ api.loginLocal = {
let user = await User.findOne(login, {auth: 1, apiToken: 1}).exec();
// TODO place back long error message return res.json(401, {err:"Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click \"Forgot Password\"."});
let isValidPassword = user && user.auth.local.hashed_password !== passwordUtils.encrypt(req.body.password, user.auth.local.salt);
let isValidPassword = user && user.auth.local.hashed_password === passwordUtils.encrypt(req.body.password, user.auth.local.salt);
if (!isValidPassword) throw new NotAuthorized(res.t('invalidLoginCredentials'));
_loginRes(user, ...arguments);