perf: 登录支持双重认证

This commit is contained in:
xiaojunnuo
2025-04-17 22:34:21 +08:00
parent 8e50e5dee3
commit 48aef25b3f
16 changed files with 132 additions and 55 deletions

View File

@@ -1,5 +1,6 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
import { TextException } from "./common-exception.js";
/**
* 授权异常
*/
@@ -10,9 +11,9 @@ export class AuthException extends BaseException {
}
export class Need2FAException extends BaseException {
constructor(message?:string) {
super('Need2FAException', Constants.res.need2fa.code, message ? message : Constants.res.need2fa.message);
export class Need2FAException extends TextException {
constructor(message:string,data:any) {
super('Need2FAException', Constants.res.need2fa.code, message ? message : Constants.res.need2fa.message,data);
}
}

View File

@@ -3,9 +3,11 @@
*/
export class BaseException extends Error {
code: number;
constructor(name, code, message) {
data?:any
constructor(name, code, message,data?:any) {
super(message);
this.name = name;
this.code = code;
this.data = data;
}
}

View File

@@ -1,16 +1,23 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
import { Constants } from "../constants.js";
import { BaseException } from "./base-exception.js";
/**
* 通用异常
*/
export class CommonException extends BaseException {
constructor(message) {
super('CommonException', Constants.res.error.code, message ? message : Constants.res.error.message);
super("CommonException", Constants.res.error.code, message ? message : Constants.res.error.message);
}
}
export class CodeException extends BaseException {
constructor(res: { code: number; message: string }) {
super('CodeException', res.code, res.message);
super("CodeException", res.code, res.message);
}
}
export class TextException extends BaseException {
constructor(name, code,message, data?) {
super(name, code, message, data);
}
}

View File

@@ -2,14 +2,15 @@ export class Result<T> {
code: number;
msg: string;
data: T;
constructor(code, msg, data?) {
this.code = code;
this.msg = msg;
this.data = data;
}
static error(code = 1, msg) {
return new Result(code, msg);
static error(code = 1, msg, data?: any) {
return new Result(code, msg, data);
}
static success(msg, data?) {