fix: addressed issues with create flow (#2458)

This commit is contained in:
Wyatt Johnson
2019-08-09 21:38:38 +00:00
committed by GitHub
parent 73040b1314
commit f2564f4eda
6 changed files with 74 additions and 24 deletions
@@ -32,4 +32,18 @@ class ErrIncorrectPassword extends TalkError {
}
}
module.exports = { ErrLocalProfile, ErrNoLocalProfile, ErrIncorrectPassword };
class ErrDuplicateLocalProfile extends TalkError {
constructor() {
super('Duplicate local profile attachment', {
translation_key: 'DUPLICATE_LOCAL_PROFILE',
status: 400,
});
}
}
module.exports = {
ErrDuplicateLocalProfile,
ErrLocalProfile,
ErrNoLocalProfile,
ErrIncorrectPassword,
};
@@ -3,6 +3,7 @@ const {
ErrNoLocalProfile,
ErrLocalProfile,
ErrIncorrectPassword,
ErrDuplicateLocalProfile,
} = require('./errors');
const { get } = require('lodash');
@@ -115,6 +116,11 @@ async function attachUserLocalAuth(ctx, email, password) {
// Validate the password.
await Users.isValidPassword(password);
// See if this email address already has a local profile setup.
if (await Users.findLocalUser(email)) {
throw new ErrDuplicateLocalProfile();
}
// Hash the new password.
const hashedPassword = await Users.hashPassword(password);
@@ -160,7 +166,7 @@ async function attachUserLocalAuth(ctx, email, password) {
await Users.sendEmailConfirmation(updatedUser, email, redirectUri);
} catch (err) {
if (err.code === 11000) {
throw new ErrEmailTaken();
throw new ErrDuplicateLocalProfile();
}
throw err;
}