mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Use lower function in the query
This commit is contained in:
parent
7dd32c3e87
commit
461b348dc0
2 changed files with 10 additions and 16 deletions
|
|
@ -42,7 +42,7 @@ import {
|
|||
hashPassword,
|
||||
setAuthInCookie,
|
||||
} from '../../utils/auth'
|
||||
import { createUser } from '../../services/create_user'
|
||||
import { createUser, getUserByEmail } from '../../services/create_user'
|
||||
import { isErrorWithCode } from '../../resolvers'
|
||||
import { AppDataSource } from '../../server'
|
||||
import { getRepository, setClaims } from '../../entity/utils'
|
||||
|
|
@ -53,7 +53,6 @@ import {
|
|||
} from '../../services/send_emails'
|
||||
import { createWebAuthToken } from './jwt_helpers'
|
||||
import { createSsoToken, ssoRedirectURL } from '../../utils/sso'
|
||||
import { ILike } from 'typeorm'
|
||||
|
||||
const logger = buildLogger('app.dispatch')
|
||||
const signToken = promisify(jwt.sign)
|
||||
|
|
@ -393,9 +392,7 @@ export function authRouter() {
|
|||
}
|
||||
const { email, password } = req.body
|
||||
try {
|
||||
const user = await getRepository(User).findOneBy({
|
||||
email: ILike(email.trim()), // case insensitive
|
||||
})
|
||||
const user = await getUserByEmail(email.trim())
|
||||
if (!user?.id) {
|
||||
return res.redirect(
|
||||
`${env.client.url}/auth/email-login?errorCodes=${LoginErrorCode.UserNotFound}`
|
||||
|
|
@ -582,9 +579,7 @@ export function authRouter() {
|
|||
}
|
||||
|
||||
try {
|
||||
const user = await getRepository(User).findOneBy({
|
||||
email: ILike(email), // case insensitive
|
||||
})
|
||||
const user = await getUserByEmail(email)
|
||||
if (!user) {
|
||||
return res.redirect(`${env.client.url}/auth/reset-sent`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export const createUser = async (input: {
|
|||
password?: string
|
||||
pendingConfirmation?: boolean
|
||||
}): Promise<[User, Profile]> => {
|
||||
const existingUser = await getUser(input.email)
|
||||
const existingUser = await getUserByEmail(input.email)
|
||||
if (existingUser) {
|
||||
if (existingUser.profile) {
|
||||
return Promise.reject({ errorCode: SignupErrorCode.UserExists })
|
||||
|
|
@ -114,11 +114,10 @@ const validateInvite = async (
|
|||
return true
|
||||
}
|
||||
|
||||
const getUser = async (email: string): Promise<User | null> => {
|
||||
const userRepo = getRepository(User)
|
||||
|
||||
return userRepo.findOne({
|
||||
where: { email: ILike(email) },
|
||||
relations: ['profile'],
|
||||
})
|
||||
export const getUserByEmail = async (email: string): Promise<User | null> => {
|
||||
return getRepository(User)
|
||||
.createQueryBuilder('user')
|
||||
.leftJoinAndSelect('user.profile', 'profile')
|
||||
.where('LOWER(email) = LOWER(:email)', { email })
|
||||
.getOne()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue