Handle both lowercase and mixedcase username/password
This commit is contained in:
parent
ba00f7fd89
commit
86e299c936
1 changed files with 8 additions and 8 deletions
|
@ -39,15 +39,15 @@ export function findUserByUsername(username, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUser(req, res, next) {
|
export function createUser(req, res, next) {
|
||||||
let { username, email } = req.body;
|
const { username, email } = req.body;
|
||||||
const { password } = req.body;
|
const { password } = req.body;
|
||||||
username = username.toLowerCase();
|
const usernameLowerCase = username.toLowerCase();
|
||||||
email = email.toLowerCase();
|
const emailLowerCase = email.toLowerCase();
|
||||||
const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date.now() + (3600000 * 24); // 24 hours
|
const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date.now() + (3600000 * 24); // 24 hours
|
||||||
random((tokenError, token) => {
|
random((tokenError, token) => {
|
||||||
const user = new User({
|
const user = new User({
|
||||||
username,
|
username: usernameLowerCase,
|
||||||
email,
|
email: emailLowerCase,
|
||||||
password,
|
password,
|
||||||
verified: User.EmailConfirmation.Sent,
|
verified: User.EmailConfirmation.Sent,
|
||||||
verifiedToken: token,
|
verifiedToken: token,
|
||||||
|
@ -57,8 +57,8 @@ export function createUser(req, res, next) {
|
||||||
User.findOne(
|
User.findOne(
|
||||||
{
|
{
|
||||||
$or: [
|
$or: [
|
||||||
{ email },
|
{ email: { $in: [ email, emailLowerCase ]} },
|
||||||
{ username }
|
{ username: { $in: [ username, usernameLowerCase ]} }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
(err, existingUser) => {
|
(err, existingUser) => {
|
||||||
|
@ -68,7 +68,7 @@ export function createUser(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
const fieldInUse = existingUser.email === email ? 'Email' : 'Username';
|
const fieldInUse = existingUser.email.toLowerCase() === emailLowerCase ? 'Email' : 'Username';
|
||||||
res.status(422).send({ error: `${fieldInUse} is in use` });
|
res.status(422).send({ error: `${fieldInUse} is in use` });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue