mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
fix: addressed issues with create flow (#2458)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user