mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
fixed backend according to migration
This commit is contained in:
parent
e255896fdc
commit
817e462698
@ -7,5 +7,4 @@ export const INALIENABLE_RIGHTS = [
|
||||
RIGHTS.CREATE_USER,
|
||||
RIGHTS.SEND_RESET_PASSWORD_EMAIL,
|
||||
RIGHTS.SET_PASSWORD,
|
||||
RIGHTS.CHECK_USERNAME,
|
||||
]
|
||||
|
||||
@ -17,7 +17,6 @@ export enum RIGHTS {
|
||||
SEND_RESET_PASSWORD_EMAIL = 'SEND_RESET_PASSWORD_EMAIL',
|
||||
SET_PASSWORD = 'SET_PASSWORD',
|
||||
UPDATE_USER_INFOS = 'UPDATE_USER_INFOS',
|
||||
CHECK_USERNAME = 'CHECK_USERNAME',
|
||||
HAS_ELOPAGE = 'HAS_ELOPAGE',
|
||||
// Admin
|
||||
SEARCH_USERS = 'SEARCH_USERS',
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
import { ArgsType, Field } from 'type-graphql'
|
||||
|
||||
@ArgsType()
|
||||
export default class CheckUsernameArgs {
|
||||
@Field(() => String)
|
||||
username: string
|
||||
}
|
||||
@ -8,12 +8,6 @@ export default class UpdateUserInfosArgs {
|
||||
@Field({ nullable: true })
|
||||
lastName?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
description?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
username?: string
|
||||
|
||||
@Field({ nullable: true })
|
||||
language?: string
|
||||
|
||||
|
||||
@ -16,8 +16,6 @@ export class User {
|
||||
this.email = json.email
|
||||
this.firstName = json.first_name
|
||||
this.lastName = json.last_name
|
||||
this.username = json.username
|
||||
this.description = json.description
|
||||
this.pubkey = json.public_hex
|
||||
this.language = json.language
|
||||
this.publisherId = json.publisher_id
|
||||
@ -37,12 +35,6 @@ export class User {
|
||||
@Field(() => String)
|
||||
lastName: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
username?: string
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
description?: string
|
||||
|
||||
@Field(() => String)
|
||||
pubkey: string
|
||||
/*
|
||||
@ -55,9 +47,6 @@ export class User {
|
||||
|
||||
@Field(() =>>> Boolean)
|
||||
emailChecked: boolean
|
||||
|
||||
@Field(() => Boolean)
|
||||
passphraseShown: boolean
|
||||
*/
|
||||
|
||||
@Field(() => String)
|
||||
@ -68,10 +57,6 @@ export class User {
|
||||
disabled: boolean
|
||||
*/
|
||||
|
||||
/* I suggest to have a group as type here
|
||||
@Field(() => ID)
|
||||
groupId: number
|
||||
*/
|
||||
// what is publisherId?
|
||||
@Field(() => Int, { nullable: true })
|
||||
publisherId?: number
|
||||
|
||||
@ -8,7 +8,6 @@ import CONFIG from '../../config'
|
||||
import { User } from '../model/User'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { encode } from '../../auth/JWT'
|
||||
import CheckUsernameArgs from '../arg/CheckUsernameArgs'
|
||||
import CreateUserArgs from '../arg/CreateUserArgs'
|
||||
import UnsecureLoginArgs from '../arg/UnsecureLoginArgs'
|
||||
import UpdateUserInfosArgs from '../arg/UpdateUserInfosArgs'
|
||||
@ -224,8 +223,6 @@ export class UserResolver {
|
||||
user.email = userEntity.email
|
||||
user.firstName = userEntity.firstName
|
||||
user.lastName = userEntity.lastName
|
||||
user.username = userEntity.username
|
||||
user.description = userEntity.description
|
||||
user.pubkey = userEntity.pubKey.toString('hex')
|
||||
user.language = userEntity.language
|
||||
|
||||
@ -278,8 +275,6 @@ export class UserResolver {
|
||||
user.email = email
|
||||
user.firstName = dbUser.firstName
|
||||
user.lastName = dbUser.lastName
|
||||
user.username = dbUser.username
|
||||
user.description = dbUser.description
|
||||
user.pubkey = dbUser.pubKey.toString('hex')
|
||||
user.language = dbUser.language
|
||||
|
||||
@ -339,13 +334,6 @@ export class UserResolver {
|
||||
language = DEFAULT_LANGUAGE
|
||||
}
|
||||
|
||||
// Validate username
|
||||
// TODO: never true
|
||||
const username = ''
|
||||
if (username.length > 3 && !this.checkUsername({ username })) {
|
||||
throw new Error('Username already in use')
|
||||
}
|
||||
|
||||
// Validate email unique
|
||||
// TODO: i can register an email in upper/lower case twice
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
@ -361,13 +349,10 @@ export class UserResolver {
|
||||
// const encryptedPrivkey = SecretKeyCryptographyEncrypt(keyPair[1], passwordHash[1])
|
||||
const emailHash = getEmailHash(email)
|
||||
|
||||
// Table: state_users
|
||||
const dbUser = new DbUser()
|
||||
dbUser.email = email
|
||||
dbUser.firstName = firstName
|
||||
dbUser.lastName = lastName
|
||||
dbUser.username = username
|
||||
dbUser.description = ''
|
||||
dbUser.emailHash = emailHash
|
||||
dbUser.language = language
|
||||
dbUser.publisherId = publisherId
|
||||
@ -591,8 +576,6 @@ export class UserResolver {
|
||||
{
|
||||
firstName,
|
||||
lastName,
|
||||
description,
|
||||
username,
|
||||
language,
|
||||
publisherId,
|
||||
password,
|
||||
@ -604,17 +587,6 @@ export class UserResolver {
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
|
||||
|
||||
if (username) {
|
||||
throw new Error('change username currently not supported!')
|
||||
// TODO: this error was thrown on login_server whenever you tried to change the username
|
||||
// to anything except "" which is an exception to the rules below. Those were defined
|
||||
// aswell, even tho never used.
|
||||
// ^[a-zA-Z][a-zA-Z0-9_-]*$
|
||||
// username must start with [a-z] or [A-Z] and than can contain also [0-9], - and _
|
||||
// username already used
|
||||
// userEntity.username = username
|
||||
}
|
||||
|
||||
if (firstName) {
|
||||
userEntity.firstName = firstName
|
||||
}
|
||||
@ -623,10 +595,6 @@ export class UserResolver {
|
||||
userEntity.lastName = lastName
|
||||
}
|
||||
|
||||
if (description) {
|
||||
userEntity.description = description
|
||||
}
|
||||
|
||||
if (language) {
|
||||
if (!isLanguage(language)) {
|
||||
throw new Error(`"${language}" isn't a valid language`)
|
||||
@ -685,30 +653,6 @@ export class UserResolver {
|
||||
return true
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.CHECK_USERNAME])
|
||||
@Query(() => Boolean)
|
||||
async checkUsername(@Args() { username }: CheckUsernameArgs): Promise<boolean> {
|
||||
// Username empty?
|
||||
if (username === '') {
|
||||
throw new Error('Username must be set.')
|
||||
}
|
||||
|
||||
// Do we fullfil the minimum character length?
|
||||
const MIN_CHARACTERS_USERNAME = 2
|
||||
if (username.length < MIN_CHARACTERS_USERNAME) {
|
||||
throw new Error(`Username must be at minimum ${MIN_CHARACTERS_USERNAME} characters long.`)
|
||||
}
|
||||
|
||||
const usersFound = await DbUser.count({ username })
|
||||
|
||||
// Username already present?
|
||||
if (usersFound !== 0) {
|
||||
throw new Error(`Username "${username}" already taken.`)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.HAS_ELOPAGE])
|
||||
@Query(() => Boolean)
|
||||
async hasElopage(@Ctx() context: any): Promise<boolean> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user