Fix: Ensure emails are processed in lower-case

This commit is contained in:
Bouncey
2019-09-10 00:02:40 +01:00
committed by mrugesh
parent e08bc32170
commit 53ca86e953
2 changed files with 18 additions and 6 deletions

View File

@ -47,7 +47,7 @@ export default function(UserIdent) {
: ''; : '';
if (!isEmail('' + email)) { if (!isEmail('' + email)) {
throw wrapHandledError( throw wrapHandledError(
new Error('invalid or empty email recieved from auth0'), new Error('invalid or empty email received from auth0'),
{ {
message: dedent` message: dedent`
${provider} did not return a valid email address. ${provider} did not return a valid email address.
@ -61,7 +61,9 @@ export default function(UserIdent) {
} }
if (provider === 'email') { if (provider === 'email') {
return User.findOne$({ where: { email } }) return User.findOne$({
where: { email: new RegExp(email.replace('.', '\\.'), 'i') }
})
.flatMap(user => { .flatMap(user => {
return user return user
? Observable.of(user) ? Observable.of(user)

View File

@ -55,6 +55,10 @@ function destroyAll(id, Model) {
return Observable.fromNodeCallback(Model.destroyAll, Model)({ userId: id }); return Observable.fromNodeCallback(Model.destroyAll, Model)({ userId: id });
} }
function ensureLowerCaseString(maybeString) {
return (maybeString && maybeString.toLowerCase()) || '';
}
function buildCompletedChallengesUpdate(completedChallenges, project) { function buildCompletedChallengesUpdate(completedChallenges, project) {
const key = Object.keys(project)[0]; const key = Object.keys(project)[0];
const solutions = project[key]; const solutions = project[key];
@ -509,10 +513,14 @@ export default function(User) {
User.prototype.requestAuthEmail = requestAuthEmail; User.prototype.requestAuthEmail = requestAuthEmail;
User.prototype.requestUpdateEmail = function requestUpdateEmail(newEmail) { function requestUpdateEmail(requestedEmail) {
const currentEmail = this.email; const newEmail = ensureLowerCaseString(requestedEmail);
const currentEmail = ensureLowerCaseString(this.email);
const isOwnEmail = isTheSame(newEmail, currentEmail); const isOwnEmail = isTheSame(newEmail, currentEmail);
const isResendUpdateToSameEmail = isTheSame(newEmail, this.newEmail); const isResendUpdateToSameEmail = isTheSame(
newEmail,
ensureLowerCaseString(this.newEmail)
);
const isLinkSentWithinLimit = getWaitMessage(this.emailVerifyTTL); const isLinkSentWithinLimit = getWaitMessage(this.emailVerifyTTL);
const isVerifiedEmail = this.emailVerified; const isVerifiedEmail = this.emailVerified;
@ -583,7 +591,9 @@ export default function(User) {
} else { } else {
return 'Something unexpected happened while updating your email.'; return 'Something unexpected happened while updating your email.';
} }
}; }
User.prototype.requestUpdateEmail = requestUpdateEmail;
User.prototype.requestUpdateFlags = async function requestUpdateFlags( User.prototype.requestUpdateFlags = async function requestUpdateFlags(
values values