mirror of
https://github.com/certd/certd.git
synced 2026-06-23 18:57:31 +08:00
chore: format
This commit is contained in:
+13
-16
@@ -4,14 +4,14 @@ import { UserSettingsService } from "../../../modules/mine/service/user-settings
|
||||
import { UserTwoFactorSetting } from "../../../modules/mine/service/models.js";
|
||||
import { merge } from "lodash-es";
|
||||
import { TwoFactorService } from "../../../modules/mine/service/two-factor-service.js";
|
||||
import {isPlus} from "@certd/plus-core";
|
||||
import { isPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller("/api/user/settings/twoFactor")
|
||||
@ApiTags(['mine'])
|
||||
@ApiTags(["mine"])
|
||||
export class UserTwoFactorSettingController extends BaseController {
|
||||
@Inject()
|
||||
service: UserSettingsService;
|
||||
@@ -19,50 +19,48 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
@Inject()
|
||||
twoFactorService: TwoFactorService;
|
||||
|
||||
|
||||
|
||||
@Post("/get", { description: Constants.per.authOnly, summary: "获取双因子认证设置" })
|
||||
async get() {
|
||||
const userId = this.getUserId();
|
||||
const setting = await this.service.getSetting<UserTwoFactorSetting>(userId,null, UserTwoFactorSetting);
|
||||
const setting = await this.service.getSetting<UserTwoFactorSetting>(userId, null, UserTwoFactorSetting);
|
||||
return this.ok(setting);
|
||||
}
|
||||
|
||||
@Post("/save", { description: Constants.per.authOnly, summary: "保存双因子认证设置" })
|
||||
async save(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通Certd专业版')
|
||||
throw new Error("本功能需要开通Certd专业版");
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
const setting = new UserTwoFactorSetting();
|
||||
merge(setting, bean);
|
||||
|
||||
// 禁用时清除
|
||||
if(!setting.authenticator.enabled){
|
||||
setting.authenticator.secret = null;
|
||||
setting.authenticator.verified = false;
|
||||
if (!setting.authenticator.enabled) {
|
||||
setting.authenticator.secret = null;
|
||||
setting.authenticator.verified = false;
|
||||
}
|
||||
|
||||
await this.service.saveSetting(userId,null, setting);
|
||||
await this.service.saveSetting(userId, null, setting);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post("/authenticator/qrcode", { description: Constants.per.authOnly, summary: "获取验证器二维码" })
|
||||
async authenticatorQrcode() {
|
||||
const userId = this.getUserId();
|
||||
const {qrcode,link,secret} = await this.twoFactorService.getAuthenticatorQrCode(userId);
|
||||
return this.ok({qrcode,link,secret});
|
||||
const { qrcode, link, secret } = await this.twoFactorService.getAuthenticatorQrCode(userId);
|
||||
return this.ok({ qrcode, link, secret });
|
||||
}
|
||||
|
||||
@Post("/authenticator/save", { description: Constants.per.authOnly, summary: "保存验证器设置" })
|
||||
async authenticatorSave(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通Certd专业版')
|
||||
throw new Error("本功能需要开通Certd专业版");
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
await this.twoFactorService.saveAuthenticator({
|
||||
userId,
|
||||
verifyCode: bean.verifyCode,
|
||||
userId,
|
||||
verifyCode: bean.verifyCode,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
@@ -73,5 +71,4 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
await this.twoFactorService.offAuthenticator(userId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user