Compare commits

..

3 Commits

2 changed files with 57 additions and 14 deletions

View File

@ -19,17 +19,18 @@ import {
import {
postApiAuthLogin,
postApiAuthRegister,
postApiAuthVerifyEmail,
postApiAccountVerifyEmail,
getApiAuthOtpGenerate,
postApiAuthOtpVerify,
postApiAuthOtpValidate,
postApiAccountOtpVerify,
postApiAccountOtpValidate,
postApiAuthOtpDisable,
PasswordResetRequest,
postApiAuthPasswordResetConfirm,
postApiAccountPasswordResetConfirm,
postApiAuthLogout,
getApiUploadLimit,
postApiAccountUpdateEmail,
} from "./account/generated/index.js";
import { AxiosResponse } from "axios";
import { AxiosError, AxiosResponse } from "axios";
export class AccountApi {
private apiUrl: string;
@ -88,7 +89,7 @@ export class AccountApi {
): Promise<boolean> {
let ret: AxiosResponse<void>;
try {
ret = await postApiAuthVerifyEmail(
ret = await postApiAccountVerifyEmail(
verifyEmailRequest,
this.buildOptions(),
);
@ -111,7 +112,10 @@ export class AccountApi {
public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise<boolean> {
let ret: AxiosResponse<void>;
try {
ret = await postApiAuthOtpVerify(otpVerifyRequest, this.buildOptions());
ret = await postApiAccountOtpVerify(
otpVerifyRequest,
this.buildOptions(),
);
} catch (e) {
return false;
}
@ -123,7 +127,7 @@ export class AccountApi {
): Promise<boolean> {
let ret: AxiosResponse<void>;
try {
ret = await postApiAuthOtpValidate(
ret = await postApiAccountOtpValidate(
otpValidateRequest,
this.buildOptions(),
);
@ -165,7 +169,7 @@ export class AccountApi {
): Promise<boolean> {
let ret: AxiosResponse<void>;
try {
ret = await postApiAuthPasswordResetConfirm(
ret = await postApiAccountPasswordResetConfirm(
passwordResetVerifyRequest,
this.buildOptions(),
);
@ -226,6 +230,23 @@ export class AccountApi {
return this.checkSuccessVal<UploadLimitResponse>(ret) ? ret.data.limit : 0;
}
public async updateEmail(
email: string,
password: string,
): Promise<boolean | Error> {
let ret: AxiosResponse<void>;
try {
ret = await postApiAccountUpdateEmail(
{ email, password },
this.buildOptions(),
);
} catch (e) {
return new Error((e as AxiosError).response.data as string);
}
return this.checkSuccessBool(ret);
}
private checkSuccessBool(ret: AxiosResponse<void>): boolean {
return ret.status === 200;
}

View File

@ -42,7 +42,7 @@ paths:
description: Successfully registered
"400":
description: Bad Request
/api/auth/verify-email:
/api/account/verify-email:
post:
summary: Verify email address
requestBody:
@ -64,7 +64,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/OTPGenerateResponse"
/api/auth/otp/verify:
/api/account/otp/verify:
post:
summary: Verify OTP for enabling two-factor authentication
requestBody:
@ -76,7 +76,7 @@ paths:
responses:
"200":
description: OTP verified successfully
/api/auth/otp/validate:
/api/account/otp/validate:
post:
summary: Validate OTP for two-factor authentication login
requestBody:
@ -100,7 +100,7 @@ paths:
responses:
"200":
description: OTP disabled successfully
/api/auth/password-reset/request:
/api/account/password-reset/request:
post:
summary: Request a password reset
requestBody:
@ -112,7 +112,7 @@ paths:
responses:
"200":
description: Password reset requested successfully
/api/auth/password-reset/confirm:
/api/account/password-reset/confirm:
post:
summary: Confirm a password reset
requestBody:
@ -148,6 +148,18 @@ paths:
$ref: "#/components/schemas/AccountInfoResponse"
"401":
description: Unauthorized
/api/account/update-email:
post:
summary: Update email address
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/UpdateEmailRequest"
responses:
"200":
description: Email updated successfully
/api/upload-limit:
get:
summary: Get the basic file upload (POST) upload limit set by the portal
@ -248,6 +260,16 @@ components:
type: string
password:
type: string
UpdateEmailRequest:
type: object
required:
- email
- password
properties:
email:
type: string
password:
type: string
PingResponse:
type: object
properties: