feat(users): add reset password functionality for users and implement forgot password page
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
API_CHANGE_PASSWORD,
|
||||
API_FORGOT_PASSWORD,
|
||||
API_PATH_GET_PROFILE,
|
||||
API_PATH_LOGIN,
|
||||
API_PATH_REFRESH_TOKEN,
|
||||
API_USERS,
|
||||
} from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
@@ -15,6 +17,15 @@ export async function apiLogin(body: MasterModel.LoginRequestBody) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiRefreshToken(
|
||||
body: MasterModel.RefreshTokenRequestBody,
|
||||
) {
|
||||
return request<MasterModel.RefreshTokenReponse>(API_PATH_REFRESH_TOKEN, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiQueryProfile() {
|
||||
return request<MasterModel.UserResponse>(API_PATH_GET_PROFILE);
|
||||
}
|
||||
@@ -40,3 +51,11 @@ export async function apiChangePassword(
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
export async function apiForgotPassword(
|
||||
body: MasterModel.ForgotPasswordRequestBody,
|
||||
) {
|
||||
return request<MasterModel.ForgotPasswordResponse>(API_FORGOT_PASSWORD, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { API_GROUPS, API_USERS, API_USERS_BY_GROUP } from '@/constants/api';
|
||||
import {
|
||||
API_GROUPS,
|
||||
API_USER_RESET_PASSWORD,
|
||||
API_USERS,
|
||||
API_USERS_BY_GROUP,
|
||||
} from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiQueryUsers(
|
||||
@@ -44,3 +49,23 @@ export async function apiDeleteUser(userId: string) {
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiResetUserPassword(
|
||||
userId: string,
|
||||
newPassword: string,
|
||||
) {
|
||||
return request(`${API_USERS}/${userId}/password`, {
|
||||
method: 'PUT',
|
||||
data: { new_password: newPassword },
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiUserResetPassword(
|
||||
body: MasterModel.UserResetPasswordRequest,
|
||||
) {
|
||||
return request(API_USER_RESET_PASSWORD, {
|
||||
method: 'PUT',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
|
||||
46
src/services/master/typings/auth.d.ts
vendored
46
src/services/master/typings/auth.d.ts
vendored
@@ -7,5 +7,51 @@ declare namespace MasterModel {
|
||||
|
||||
interface LoginResponse {
|
||||
token?: string;
|
||||
refresh_token: string;
|
||||
enabled_2fa: boolean;
|
||||
}
|
||||
interface RefreshTokenRequestBody {
|
||||
refresh_token: string;
|
||||
}
|
||||
interface RefreshTokenReponse {
|
||||
access_token: string;
|
||||
}
|
||||
|
||||
interface TokenParsed {
|
||||
exp: number;
|
||||
iat: number;
|
||||
iss: string;
|
||||
sub: string;
|
||||
issuer_id: string;
|
||||
type: number;
|
||||
purpose: 'access' | 'refresh';
|
||||
}
|
||||
interface RefreshTokenParsed extends TokenParsed {
|
||||
jti: string;
|
||||
}
|
||||
|
||||
interface TokenParsedTransformed {
|
||||
expriresAt: number;
|
||||
issuedAt: number;
|
||||
issuer: string;
|
||||
/** User Email */
|
||||
subject: string;
|
||||
issuerId: string;
|
||||
type: number;
|
||||
purpose: 'access' | 'refresh';
|
||||
}
|
||||
|
||||
interface RefreshTokenParsedTransformed extends TokenParsedTransformed {
|
||||
jwtID: string;
|
||||
}
|
||||
|
||||
interface ForgotPasswordRequestBody {
|
||||
email: string;
|
||||
host: string;
|
||||
}
|
||||
|
||||
interface ForgotPasswordResponse {
|
||||
message: string;
|
||||
error?: string;
|
||||
}
|
||||
}
|
||||
|
||||
5
src/services/master/typings/user.d.ts
vendored
5
src/services/master/typings/user.d.ts
vendored
@@ -41,4 +41,9 @@ declare namespace MasterModel {
|
||||
limit?: number;
|
||||
users: UserResponse[];
|
||||
}
|
||||
interface UserResetPasswordRequest {
|
||||
token: string;
|
||||
password: string;
|
||||
confirm_password?: string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user