Prevented users from signing up with an email/username which was already present in the migration database.
This commit is contained in:
parent
a1b602efdb
commit
da9428205f
4 changed files with 79 additions and 7 deletions
|
|
@ -43,7 +43,7 @@ module.exports.post = async function(req, res){
|
|||
|
||||
//Check to make sure the user is logged in
|
||||
if(req.session.user == null){
|
||||
errorHandler(res, "Invalid user!");
|
||||
return errorHandler(res, "Invalid user!");
|
||||
}
|
||||
|
||||
//Authenticate and find user model from DB
|
||||
|
|
@ -51,11 +51,22 @@ module.exports.post = async function(req, res){
|
|||
|
||||
//If we have an invalid user
|
||||
if(userDB == null){
|
||||
errorHandler(res, "Invalid user!");
|
||||
return errorHandler(res, "Invalid user!");
|
||||
}
|
||||
|
||||
if(userDB.email == email){
|
||||
errorHandler(res, "Cannot set current email!");
|
||||
return errorHandler(res, "Cannot set current email!");
|
||||
}
|
||||
|
||||
|
||||
//Look through DB and migration cache for existing email
|
||||
const existingDB = await userModel.findOne({email: new RegExp(email, 'i')});
|
||||
const needsMigration = userModel.migrationCache.emails.includes(email.toLowerCase());
|
||||
|
||||
//If the email is in use
|
||||
if(existingDB != null || needsMigration){
|
||||
//Complain
|
||||
return errorHandler(res, "Email already in use!");
|
||||
}
|
||||
|
||||
//Generate the password reset link
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue