mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
Merge pull request #1037 from gradido/login_call_checkUsername
login_call_check_username
This commit is contained in:
commit
bf6d6a50de
@ -4,7 +4,4 @@ import { ArgsType, Field } from 'type-graphql'
|
||||
export default class CheckUsernameArgs {
|
||||
@Field(() => String)
|
||||
username: string
|
||||
|
||||
@Field(() => Number, { nullable: true })
|
||||
groupId?: number
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
|
||||
@ObjectType()
|
||||
export class CheckUsernameResponse {
|
||||
constructor(json: any) {
|
||||
this.state = json.state
|
||||
this.msg = json.msg
|
||||
this.groupId = json.group_id
|
||||
}
|
||||
|
||||
@Field(() => String)
|
||||
state: string
|
||||
|
||||
@Field(() => String)
|
||||
msg?: string
|
||||
|
||||
@Field(() => Number)
|
||||
groupId?: number
|
||||
}
|
||||
@ -3,8 +3,8 @@
|
||||
|
||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||
import { from_hex as fromHex } from 'libsodium-wrappers'
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import CONFIG from '../../config'
|
||||
import { CheckUsernameResponse } from '../model/CheckUsernameResponse'
|
||||
import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode'
|
||||
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
||||
import { UpdateUserInfosResponse } from '../model/UpdateUserInfosResponse'
|
||||
@ -22,10 +22,10 @@ import {
|
||||
klicktippNewsletterStateMiddleware,
|
||||
} from '../../middleware/klicktippMiddleware'
|
||||
import { CheckEmailResponse } from '../model/CheckEmailResponse'
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import { UserSettingRepository } from '../../typeorm/repository/UserSettingRepository'
|
||||
import { Setting } from '../enum/Setting'
|
||||
import { UserRepository } from '../../typeorm/repository/User'
|
||||
import { LoginUser } from '@entity/LoginUser'
|
||||
|
||||
@Resolver()
|
||||
export class UserResolver {
|
||||
@ -275,15 +275,27 @@ export class UserResolver {
|
||||
return response
|
||||
}
|
||||
|
||||
@Query(() => CheckUsernameResponse)
|
||||
async checkUsername(
|
||||
@Args() { username, groupId = 1 }: CheckUsernameArgs,
|
||||
): Promise<CheckUsernameResponse> {
|
||||
const response = await apiGet(
|
||||
CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`,
|
||||
)
|
||||
if (!response.success) throw new Error(response.data)
|
||||
return new CheckUsernameResponse(response.data)
|
||||
@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 LoginUser.count({ username })
|
||||
|
||||
// Username already present?
|
||||
if (usersFound !== 0) {
|
||||
throw new Error(`Username "${username}" already taken.`)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Query(() => CheckEmailResponse)
|
||||
|
||||
56
database/entity/0003-login_server_tables/LoginUser.ts
Normal file
56
database/entity/0003-login_server_tables/LoginUser.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
|
||||
// Moriz: I do not like the idea of having two user tables
|
||||
@Entity('login_users')
|
||||
export class LoginUser extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ length: 191, unique: true })
|
||||
email: string
|
||||
|
||||
@Column({ name: 'first_name', length: 150 })
|
||||
firstName: string
|
||||
|
||||
@Column({ name: 'last_name', length: 255, default: '' })
|
||||
lastName: string
|
||||
|
||||
@Column({ length: 255, default: '' })
|
||||
username: string
|
||||
|
||||
@Column({ default: '' })
|
||||
description: string
|
||||
|
||||
@Column({ type: 'bigint', default: 0, unsigned: true })
|
||||
password: string
|
||||
|
||||
@Column({ name: 'pubkey', type: 'binary', length: 32, default: null, nullable: true })
|
||||
pubKey: Buffer
|
||||
|
||||
@Column({ name: 'privkey', type: 'binary', length: 80, default: null, nullable: true })
|
||||
privKey: Buffer
|
||||
|
||||
@Column({ name: 'email_hash', type: 'binary', length: 32, default: null, nullable: true })
|
||||
emailHash: Buffer
|
||||
|
||||
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP' })
|
||||
createdAt: Date
|
||||
|
||||
@Column({ name: 'email_checked', default: 0 })
|
||||
emailChecked: boolean
|
||||
|
||||
@Column({ name: 'passphrase_shown', default: 0 })
|
||||
passphraseShown: boolean
|
||||
|
||||
@Column({ length: 4, default: 'de' })
|
||||
language: string
|
||||
|
||||
@Column({ default: 0 })
|
||||
disabled: boolean
|
||||
|
||||
@Column({ name: 'group_id', default: 0, unsigned: true })
|
||||
groupId: number
|
||||
|
||||
@Column({ name: 'publisher_id', default: 0 })
|
||||
publisherId: number
|
||||
}
|
||||
1
database/entity/LoginUser.ts
Normal file
1
database/entity/LoginUser.ts
Normal file
@ -0,0 +1 @@
|
||||
export { LoginUser } from './0003-login_server_tables/LoginUser'
|
||||
@ -1,4 +1,5 @@
|
||||
import { Balance } from './Balance'
|
||||
import { LoginUser } from './LoginUser'
|
||||
import { Migration } from './Migration'
|
||||
import { Transaction } from './Transaction'
|
||||
import { TransactionCreation } from './TransactionCreation'
|
||||
@ -9,6 +10,7 @@ import { UserTransaction } from './UserTransaction'
|
||||
|
||||
export const entities = [
|
||||
Balance,
|
||||
LoginUser,
|
||||
Migration,
|
||||
Transaction,
|
||||
TransactionCreation,
|
||||
|
||||
@ -75,9 +75,7 @@ export const sendResetPasswordEmail = gql`
|
||||
|
||||
export const checkUsername = gql`
|
||||
query($username: String!) {
|
||||
checkUsername(username: $username) {
|
||||
state
|
||||
}
|
||||
checkUsername(username: $username)
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ export const loadAllRules = (i18nCallback) => {
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
return result.data.checkUsername.state === 'success'
|
||||
return result.data.checkUsername
|
||||
})
|
||||
.catch(() => {
|
||||
return false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user