Merge pull request #1542 from gradido/fix_upper_case_register

Fix: Upper case email on register breaks account
This commit is contained in:
Ulf Gebhardt 2022-02-28 12:06:56 +01:00 committed by GitHub
commit 35681f1595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import dotenv from 'dotenv'
dotenv.config()
const constants = {
DB_VERSION: '0024-combine_transaction_tables',
DB_VERSION: '0025-emails_to_lower',
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
}

View File

@ -335,7 +335,7 @@ export class UserResolver {
}
// Validate email unique
// TODO: i can register an email in upper/lower case twice
email = email.trim().toLowerCase()
// TODO we cannot use repository.count(), since it does not allow to specify if you want to include the soft deletes
const userFound = await DbUser.findOne({ email }, { withDeleted: true })
if (userFound) {
@ -408,6 +408,7 @@ export class UserResolver {
@Authorized([RIGHTS.SEND_ACTIVATION_EMAIL])
@Mutation(() => Boolean)
async sendActivationEmail(@Arg('email') email: string): Promise<boolean> {
email = email.trim().toLowerCase()
const user = await DbUser.findOneOrFail({ email: email })
const queryRunner = getConnection().createQueryRunner()
@ -448,7 +449,7 @@ export class UserResolver {
@Query(() => Boolean)
async sendResetPasswordEmail(@Arg('email') email: string): Promise<boolean> {
// TODO: this has duplicate code with createUser
email = email.trim().toLowerCase()
const user = await DbUser.findOneOrFail({ email })
const optInCode = await getOptInCode(user.id)

View File

@ -0,0 +1,17 @@
/* MIGRATION TO MAKE ALL EMAILS LOWERCASE
*
* Make all `email` values in `users` lowercase.
* This allows safe queries without any modificators
*/
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn('UPDATE `users` SET `email` = LOWER(`email`);')
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// This migration cannot be revered
}