Can replace user password from profile
This commit is contained in:
@ -11,6 +11,14 @@ export interface User {
|
||||
has_password: boolean;
|
||||
}
|
||||
|
||||
export enum ReplacePasswordResponse {
|
||||
Error,
|
||||
Success,
|
||||
InvalidOldPassword,
|
||||
InvalidNewPassword,
|
||||
TooManyRequests,
|
||||
}
|
||||
|
||||
export class UserApi {
|
||||
/**
|
||||
* Get current user information
|
||||
@ -36,4 +44,39 @@ export class UserApi {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace user password
|
||||
*/
|
||||
static async ReplacePassword(
|
||||
oldPwd: string,
|
||||
newPwd: string
|
||||
): Promise<ReplacePasswordResponse> {
|
||||
const res = await APIClient.exec({
|
||||
uri: "/user/replace_password",
|
||||
method: "POST",
|
||||
jsonData: {
|
||||
old_password: oldPwd,
|
||||
new_password: newPwd,
|
||||
},
|
||||
allowFail: true,
|
||||
});
|
||||
|
||||
if (res.status >= 200 && res.status < 300)
|
||||
return ReplacePasswordResponse.Success;
|
||||
|
||||
switch (res.status) {
|
||||
case 400:
|
||||
return ReplacePasswordResponse.InvalidNewPassword;
|
||||
|
||||
case 401:
|
||||
return ReplacePasswordResponse.InvalidOldPassword;
|
||||
|
||||
case 429:
|
||||
return ReplacePasswordResponse.TooManyRequests;
|
||||
|
||||
default:
|
||||
return ReplacePasswordResponse.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user