constants to upper case

This commit is contained in:
Moriz Wahl 2023-05-17 16:24:05 +02:00
parent b11238a35b
commit 85bfcd9df3
2 changed files with 7 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import { validate, version } from 'uuid'
import { LogError } from '@/server/LogError'
import { validAliasRegex } from './validateAlias'
import { VALID_ALIAS_REGEX } from './validateAlias'
export const findUserByIdentifier = async (identifier: string): Promise<DbUser> => {
let user: DbUser | undefined
@ -29,7 +29,7 @@ export const findUserByIdentifier = async (identifier: string): Promise<DbUser>
}
user = userContact.user
user.emailContact = userContact
} else if (validAliasRegex.exec(identifier)) {
} else if (VALID_ALIAS_REGEX.exec(identifier)) {
user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] })
if (!user) {
throw new LogError('No user found to given identifier', identifier)

View File

@ -4,9 +4,9 @@ import { User as DbUser } from '@entity/User'
import { LogError } from '@/server/LogError'
// 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',
'email',
'gast',
@ -27,8 +27,9 @@ const reservedAlias = [
export const validateAlias = async (alias: string): Promise<boolean> => {
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.match(validAliasRegex)) throw new LogError('Invalid characters in alias', alias)
if (reservedAlias.includes(alias.toLowerCase())) throw new LogError('Alias is not allowed', alias)
if (!alias.match(VALID_ALIAS_REGEX)) throw new LogError('Invalid characters in alias', alias)
if (RESERVED_ALIAS.includes(alias.toLowerCase()))
throw new LogError('Alias is not allowed', alias)
const aliasInUse = await DbUser.find({
where: { alias: Raw((a) => `LOWER(${a}) = "${alias.toLowerCase()}"`) },
})