diff --git a/api-server/common/models/User-Identity.js b/api-server/common/models/User-Identity.js index e028fd3ce6..e67dc20d92 100644 --- a/api-server/common/models/User-Identity.js +++ b/api-server/common/models/User-Identity.js @@ -47,7 +47,7 @@ export default function(UserIdent) { : ''; if (!isEmail('' + email)) { throw wrapHandledError( - new Error('invalid or empty email recieved from auth0'), + new Error('invalid or empty email received from auth0'), { message: dedent` ${provider} did not return a valid email address. @@ -61,7 +61,9 @@ export default function(UserIdent) { } if (provider === 'email') { - return User.findOne$({ where: { email } }) + return User.findOne$({ + where: { email: new RegExp(email.replace('.', '\\.'), 'i') } + }) .flatMap(user => { return user ? Observable.of(user) diff --git a/api-server/common/models/user.js b/api-server/common/models/user.js index 65d8a18499..87d55bc11c 100644 --- a/api-server/common/models/user.js +++ b/api-server/common/models/user.js @@ -55,6 +55,10 @@ function destroyAll(id, Model) { return Observable.fromNodeCallback(Model.destroyAll, Model)({ userId: id }); } +function ensureLowerCaseString(maybeString) { + return (maybeString && maybeString.toLowerCase()) || ''; +} + function buildCompletedChallengesUpdate(completedChallenges, project) { const key = Object.keys(project)[0]; const solutions = project[key]; @@ -509,10 +513,14 @@ export default function(User) { User.prototype.requestAuthEmail = requestAuthEmail; - User.prototype.requestUpdateEmail = function requestUpdateEmail(newEmail) { - const currentEmail = this.email; + function requestUpdateEmail(requestedEmail) { + const newEmail = ensureLowerCaseString(requestedEmail); + const currentEmail = ensureLowerCaseString(this.email); const isOwnEmail = isTheSame(newEmail, currentEmail); - const isResendUpdateToSameEmail = isTheSame(newEmail, this.newEmail); + const isResendUpdateToSameEmail = isTheSame( + newEmail, + ensureLowerCaseString(this.newEmail) + ); const isLinkSentWithinLimit = getWaitMessage(this.emailVerifyTTL); const isVerifiedEmail = this.emailVerified; @@ -583,7 +591,9 @@ export default function(User) { } else { return 'Something unexpected happened while updating your email.'; } - }; + } + + User.prototype.requestUpdateEmail = requestUpdateEmail; User.prototype.requestUpdateFlags = async function requestUpdateFlags( values