mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
constants to upper case
This commit is contained in:
parent
b11238a35b
commit
85bfcd9df3
@ -4,7 +4,7 @@ import { validate, version } from 'uuid'
|
|||||||
|
|
||||||
import { LogError } from '@/server/LogError'
|
import { LogError } from '@/server/LogError'
|
||||||
|
|
||||||
import { validAliasRegex } from './validateAlias'
|
import { VALID_ALIAS_REGEX } from './validateAlias'
|
||||||
|
|
||||||
export const findUserByIdentifier = async (identifier: string): Promise<DbUser> => {
|
export const findUserByIdentifier = async (identifier: string): Promise<DbUser> => {
|
||||||
let user: DbUser | undefined
|
let user: DbUser | undefined
|
||||||
@ -29,7 +29,7 @@ export const findUserByIdentifier = async (identifier: string): Promise<DbUser>
|
|||||||
}
|
}
|
||||||
user = userContact.user
|
user = userContact.user
|
||||||
user.emailContact = userContact
|
user.emailContact = userContact
|
||||||
} else if (validAliasRegex.exec(identifier)) {
|
} else if (VALID_ALIAS_REGEX.exec(identifier)) {
|
||||||
user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] })
|
user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] })
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new LogError('No user found to given identifier', identifier)
|
throw new LogError('No user found to given identifier', identifier)
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import { User as DbUser } from '@entity/User'
|
|||||||
import { LogError } from '@/server/LogError'
|
import { LogError } from '@/server/LogError'
|
||||||
|
|
||||||
// eslint-disable-next-line security/detect-unsafe-regex
|
// eslint-disable-next-line security/detect-unsafe-regex
|
||||||
export const validAliasRegex = /^(?=.{3,20}$)[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+?)*$/
|
export const VALID_ALIAS_REGEX = /^(?=.{3,20}$)[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+?)*$/
|
||||||
|
|
||||||
const reservedAlias = [
|
const RESERVED_ALIAS = [
|
||||||
'admin',
|
'admin',
|
||||||
'email',
|
'email',
|
||||||
'gast',
|
'gast',
|
||||||
@ -27,8 +27,9 @@ const reservedAlias = [
|
|||||||
export const validateAlias = async (alias: string): Promise<boolean> => {
|
export const validateAlias = async (alias: string): Promise<boolean> => {
|
||||||
if (alias.length < 3) throw new LogError('Given alias is too short', alias)
|
if (alias.length < 3) throw new LogError('Given alias is too short', alias)
|
||||||
if (alias.length > 20) throw new LogError('Given alias is too long', alias)
|
if (alias.length > 20) throw new LogError('Given alias is too long', alias)
|
||||||
if (!alias.match(validAliasRegex)) throw new LogError('Invalid characters in alias', alias)
|
if (!alias.match(VALID_ALIAS_REGEX)) throw new LogError('Invalid characters in alias', alias)
|
||||||
if (reservedAlias.includes(alias.toLowerCase())) throw new LogError('Alias is not allowed', alias)
|
if (RESERVED_ALIAS.includes(alias.toLowerCase()))
|
||||||
|
throw new LogError('Alias is not allowed', alias)
|
||||||
const aliasInUse = await DbUser.find({
|
const aliasInUse = await DbUser.find({
|
||||||
where: { alias: Raw((a) => `LOWER(${a}) = "${alias.toLowerCase()}"`) },
|
where: { alias: Raw((a) => `LOWER(${a}) = "${alias.toLowerCase()}"`) },
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user