mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1542 from gradido/fix_upper_case_register
Fix: Upper case email on register breaks account
This commit is contained in:
commit
35681f1595
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
17
database/migrations/0025-emails_to_lower.ts
Normal file
17
database/migrations/0025-emails_to_lower.ts
Normal 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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user