Files
certd/packages/ui/certd-client/src/store/user/api.user.ts
T

148 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-04-12 23:59:03 +08:00
import { request } from "/src/api/service";
2023-06-27 09:29:43 +08:00
export interface RegisterReq {
username: string;
password: string;
confirmPassword: string;
}
2023-01-29 13:44:19 +08:00
/**
* @description: Login interface parameters
*/
export interface LoginReq {
username: string;
password: string;
}
2024-11-28 17:36:45 +08:00
export interface SmsLoginReq {
mobile: string;
phoneCode: string;
smsCode: string;
randomStr: string;
}
2025-07-24 16:56:22 +08:00
export interface ForgotPasswordReq {
forgotPasswordType: string;
input: string;
randomStr: string;
imgCode: string;
validateCode: string;
password: string;
confirmPassword: string;
}
2023-01-29 13:44:19 +08:00
export interface UserInfoRes {
id: string | number;
username: string;
nickName: string;
avatar?: string;
2024-10-15 12:01:38 +08:00
roleIds: number[];
2024-11-30 22:35:26 +08:00
isWeak?: boolean;
2025-06-04 23:00:37 +08:00
validTime?: number;
status?: number;
2023-01-29 13:44:19 +08:00
}
export interface LoginRes {
token: string;
expire: number;
}
2023-06-27 09:29:43 +08:00
export async function register(user: RegisterReq): Promise<UserInfoRes> {
return await request({
url: "/register",
method: "post",
2025-04-12 23:59:03 +08:00
data: user,
2023-06-27 09:29:43 +08:00
});
}
2025-07-24 16:56:22 +08:00
export async function forgotPassword(data: ForgotPasswordReq): Promise<any> {
return await request({
url: "/forgotPassword",
method: "post",
data: data,
});
}
export async function logout() {
return await request({
url: "/logout",
method: "post",
});
}
2023-06-27 09:29:43 +08:00
2023-01-29 13:44:19 +08:00
export async function login(data: LoginReq): Promise<LoginRes> {
//如果开启了登录与权限模块,则真实登录
return await request({
url: "/login",
method: "post",
2025-04-12 23:59:03 +08:00
data,
2023-01-29 13:44:19 +08:00
});
}
2024-11-28 17:36:45 +08:00
export async function loginBySms(data: SmsLoginReq): Promise<LoginRes> {
//如果开启了登录与权限模块,则真实登录
return await request({
url: "/loginBySms",
method: "post",
2025-04-12 23:59:03 +08:00
data,
2024-11-28 17:36:45 +08:00
});
}
2023-01-29 13:44:19 +08:00
export async function mine(): Promise<UserInfoRes> {
return await request({
2024-08-14 21:24:12 +08:00
url: "/mine/info",
2025-04-12 23:59:03 +08:00
method: "post",
2024-08-14 21:24:12 +08:00
});
}
2025-04-17 22:34:21 +08:00
export async function loginByTwoFactor(data: any) {
return await request({
url: "/loginByTwoFactor",
method: "post",
data,
});
}
2025-12-01 00:40:46 +08:00
export async function OauthProviders() {
return await request({
url: "/oauth/providers",
method: "post",
});
}
2026-03-12 18:11:02 +08:00
export async function generatePasskeyRegistrationOptions() {
return await request({
url: "/passkey/generateRegistration",
method: "post",
});
}
2026-03-13 15:31:03 +08:00
export async function verifyPasskeyRegistration(response: any, challenge: string) {
2026-03-12 18:11:02 +08:00
return await request({
url: "/passkey/verifyRegistration",
method: "post",
2026-03-13 15:31:03 +08:00
data: { response, challenge },
2026-03-12 18:11:02 +08:00
});
}
2026-03-13 15:31:03 +08:00
export async function generatePasskeyAuthenticationOptions() {
2026-03-12 18:11:02 +08:00
return await request({
url: "/passkey/generateAuthentication",
method: "post",
});
}
2026-03-13 15:31:03 +08:00
export async function loginByPasskey(form: { credential: any; challenge: string }) {
2026-03-12 18:11:02 +08:00
return await request({
url: "/loginByPasskey",
method: "post",
data: form,
});
}
2026-03-13 15:31:03 +08:00
export async function registerPasskey(form: { response: any; challenge: string }) {
2026-03-12 18:11:02 +08:00
return await request({
url: "/passkey/register",
method: "post",
data: form,
});
}