mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Implementation of the Arguments and the Response classes for the loginAPIs. Implementation of the used API calls in Apollo.
This commit is contained in:
parent
32eeda69b2
commit
bb5b70d5f6
@ -23,9 +23,6 @@ export const apiGet = async (url: string): Promise<any> => {
|
|||||||
return axios
|
return axios
|
||||||
.get(url)
|
.get(url)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('IN apiGet.THEN: ' + JSON.stringify({ success: true, result: result }))
|
|
||||||
|
|
||||||
if (result.status !== 200) {
|
if (result.status !== 200) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('IN status: ' + 'HTTP Status Error ' + result.status)
|
console.log('IN status: ' + 'HTTP Status Error ' + result.status)
|
||||||
@ -33,7 +30,7 @@ export const apiGet = async (url: string): Promise<any> => {
|
|||||||
}
|
}
|
||||||
if (!['success', 'warning'].includes(result.data.state)) {
|
if (!['success', 'warning'].includes(result.data.state)) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('IN state: ' + result.data.state + ' message: ' + result.data.msg)
|
console.log('IN state: ' + result.data.state + ' message: ' + JSON.stringify(result))
|
||||||
throw new Error(result.data.msg)
|
throw new Error(result.data.msg)
|
||||||
}
|
}
|
||||||
return { success: true, result: result }
|
return { success: true, result: result }
|
||||||
|
|||||||
@ -25,3 +25,87 @@ export class UnsecureLoginArgs {
|
|||||||
@Field(() => String)
|
@Field(() => String)
|
||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class CreateUserArgs {
|
||||||
|
@Field(() => String)
|
||||||
|
email: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
firstName: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
lastName: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class SendEmailArgs {
|
||||||
|
@Field(() => String)
|
||||||
|
email: string
|
||||||
|
|
||||||
|
@Field(() => Number)
|
||||||
|
emailText: number
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
emailVerificationCodeType: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class GetUserInfoArgs {
|
||||||
|
@Field(() => Number)
|
||||||
|
sessionId: number
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
email: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class ChangePasswordArgs {
|
||||||
|
@Field(() => Number)
|
||||||
|
sessionId: number
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
email: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class UpdateUserInfosArgs {
|
||||||
|
@Field(() => Number)
|
||||||
|
sessionId!: number
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
email!: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
firstName?: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
lastName?: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
username?: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
language?: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
password?: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
passwordNew?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ArgsType()
|
||||||
|
export class CheckUsernameArgs {
|
||||||
|
@Field(() => String)
|
||||||
|
username: string
|
||||||
|
|
||||||
|
@Field(() => Number)
|
||||||
|
groupId?: number
|
||||||
|
}
|
||||||
@ -95,3 +95,104 @@ export class LoginViaVerificationCode extends BaseEntity {
|
|||||||
@Column()
|
@Column()
|
||||||
email: string
|
email: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class LogoutResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class CreateResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class SendEmailResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
msg?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class Server extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
loginServerPath: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class ErrorData extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
messages: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class GetUserInfoResponse extends BaseEntity {
|
||||||
|
/* "state": "success",
|
||||||
|
"userData": {
|
||||||
|
"EmailVerificationCode.Register": "2718271129122",
|
||||||
|
"pubkeyhex": "131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6",
|
||||||
|
"first_name": "Max",
|
||||||
|
"last_name": "Musterman",
|
||||||
|
"disabled": 0,
|
||||||
|
"email_checked": 1
|
||||||
|
},
|
||||||
|
"server": {
|
||||||
|
"loginServer.path": "http://localhost/account"
|
||||||
|
},
|
||||||
|
"errors": []
|
||||||
|
*/
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
|
||||||
|
@Field(() => User)
|
||||||
|
userData: User
|
||||||
|
|
||||||
|
@Field(() => Server)
|
||||||
|
server: Server
|
||||||
|
|
||||||
|
@Field(() => [ErrorData])
|
||||||
|
errors: [ErrorData]
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class ChangePasswordResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class UpdateUserInfosResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
|
||||||
|
@Field(() => Number)
|
||||||
|
validValues: number
|
||||||
|
|
||||||
|
@Field(() => [ErrorData])
|
||||||
|
errors: [ErrorData]
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
@ObjectType()
|
||||||
|
export class CheckUsernameResponse extends BaseEntity {
|
||||||
|
@Field(() => String)
|
||||||
|
state: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
msg?: string
|
||||||
|
|
||||||
|
@Field(() => Number)
|
||||||
|
groupId?: number
|
||||||
|
}
|
||||||
|
|||||||
@ -1,22 +1,30 @@
|
|||||||
// import jwt from 'jsonwebtoken'
|
// import jwt from 'jsonwebtoken'
|
||||||
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
|
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
|
||||||
import CONFIG from '../../config'
|
import CONFIG from '../../config'
|
||||||
import { LoginResponse, LoginViaVerificationCode } from '../models/User'
|
import {
|
||||||
import { UnsecureLoginArgs } from '../inputs/LoginUserInput'
|
ChangePasswordResponse,
|
||||||
|
CheckUsernameResponse,
|
||||||
|
CreateResponse,
|
||||||
|
GetUserInfoResponse,
|
||||||
|
LoginResponse,
|
||||||
|
LoginViaVerificationCode,
|
||||||
|
LogoutResponse,
|
||||||
|
SendEmailResponse,
|
||||||
|
UpdateUserInfosResponse,
|
||||||
|
} from '../models/User'
|
||||||
|
import {
|
||||||
|
ChangePasswordArgs,
|
||||||
|
CheckUsernameArgs,
|
||||||
|
CreateUserArgs,
|
||||||
|
GetUserInfoArgs,
|
||||||
|
SendEmailArgs,
|
||||||
|
UnsecureLoginArgs,
|
||||||
|
UpdateUserInfosArgs,
|
||||||
|
} from '../inputs/LoginUserInput'
|
||||||
import { apiPost, apiGet } from '../../apis/loginAPI'
|
import { apiPost, apiGet } from '../../apis/loginAPI'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class UserResolver {
|
export class UserResolver {
|
||||||
/* @Query(() => [User])
|
|
||||||
users(): Promise<User[]> {
|
|
||||||
return User.find()
|
|
||||||
} */
|
|
||||||
|
|
||||||
/* @Query(() => User)
|
|
||||||
user(@Arg('id') id: string): Promise<User | undefined> {
|
|
||||||
return User.findOne({ where: { id } })
|
|
||||||
} */
|
|
||||||
|
|
||||||
@Query(() => LoginResponse)
|
@Query(() => LoginResponse)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<any> {
|
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<any> {
|
||||||
@ -55,20 +63,6 @@ export class UserResolver {
|
|||||||
// return loginResult.user ? loginResult.user : new User()
|
// return loginResult.user ? loginResult.user : new User()
|
||||||
}
|
}
|
||||||
|
|
||||||
// forgot password request
|
|
||||||
@Query(() => String)
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
async sendEmail(@Arg('email') email: string): Promise<any> {
|
|
||||||
const payload = {
|
|
||||||
email,
|
|
||||||
email_text: 7,
|
|
||||||
email_verification_code_type: 'resetPassword',
|
|
||||||
}
|
|
||||||
const result = await apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload)
|
|
||||||
if (result.success) return result.result.data.state
|
|
||||||
return result.result
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query(() => LoginViaVerificationCode)
|
@Query(() => LoginViaVerificationCode)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
async loginViaEmailVerificationCode(@Arg('optin') optin: string): Promise<any> {
|
async loginViaEmailVerificationCode(@Arg('optin') optin: string): Promise<any> {
|
||||||
@ -84,4 +78,92 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
return result.result
|
return result.result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Query(() => LogoutResponse)
|
||||||
|
async logout(@Arg('sessionId') sessionId: number): Promise<any> {
|
||||||
|
const payload = { session_id: sessionId }
|
||||||
|
const result = apiPost(CONFIG.LOGIN_API_URL + 'logout', payload);
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => CreateResponse)
|
||||||
|
async create(@Args() { email, firstName, lastName, password }: CreateUserArgs): Promise<any> {
|
||||||
|
const payload = {
|
||||||
|
email,
|
||||||
|
first_name: firstName,
|
||||||
|
last_name: lastName,
|
||||||
|
password,
|
||||||
|
emailType: 2,
|
||||||
|
login_after_register: true,
|
||||||
|
}
|
||||||
|
return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => SendEmailResponse)
|
||||||
|
async sendEmail(
|
||||||
|
@Args()
|
||||||
|
{ email, emailText = 7, emailVerificationCodeType = 'resetPassword' }: SendEmailArgs,
|
||||||
|
): Promise<any> {
|
||||||
|
const payload = {
|
||||||
|
email,
|
||||||
|
email_text: emailText,
|
||||||
|
email_verification_code_type: emailVerificationCodeType,
|
||||||
|
}
|
||||||
|
return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => GetUserInfoResponse)
|
||||||
|
async getUserInfos(@Args() { sessionId, email }: GetUserInfoArgs): Promise<any> {
|
||||||
|
const payload = {
|
||||||
|
session_id: sessionId,
|
||||||
|
email: email,
|
||||||
|
ask: ['user.first_name', 'user.last_name'],
|
||||||
|
}
|
||||||
|
return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => ChangePasswordResponse)
|
||||||
|
async changePassword(@Args() { sessionId, email, password }: ChangePasswordArgs): Promise<any> {
|
||||||
|
const payload = {
|
||||||
|
session_id: sessionId,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
}
|
||||||
|
return apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => UpdateUserInfosResponse)
|
||||||
|
async updateUserInfos(
|
||||||
|
@Args()
|
||||||
|
{
|
||||||
|
sessionId,
|
||||||
|
email,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
password,
|
||||||
|
passwordNew,
|
||||||
|
}: UpdateUserInfosArgs,
|
||||||
|
): Promise<any> {
|
||||||
|
const payload = {
|
||||||
|
session_id: sessionId,
|
||||||
|
email,
|
||||||
|
update: {
|
||||||
|
'User.first_name': firstName,
|
||||||
|
'User.last_name': lastName,
|
||||||
|
// 'User.description': data.description,
|
||||||
|
'User.username': username,
|
||||||
|
'User.language': language,
|
||||||
|
'User.password_old': password,
|
||||||
|
'User.password': passwordNew,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => CheckUsernameResponse)
|
||||||
|
async checkUsername(@Args() { username, groupId = 1 }: CheckUsernameArgs): Promise<any> {
|
||||||
|
return apiGet(CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user