chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,41 +1,41 @@
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { EmailService } from '../../../modules/basic/service/email-service.js';
import { ApiTags } from '@midwayjs/swagger';
import { Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
import { BaseController } from "@certd/lib-server";
import { Constants } from "@certd/lib-server";
import { EmailService } from "../../../modules/basic/service/email-service.js";
import { ApiTags } from "@midwayjs/swagger";
/**
*/
@Provide()
@Controller('/api/mine/email')
@ApiTags(['mine'])
@Controller("/api/mine/email")
@ApiTags(["mine"])
export class EmailController extends BaseController {
@Inject()
emailService: EmailService;
@Post('/test', { description: Constants.per.authOnly, summary: "测试邮件发送" })
public async test(@Body('receiver') receiver) {
@Post("/test", { description: Constants.per.authOnly, summary: "测试邮件发送" })
public async test(@Body("receiver") receiver) {
const userId = super.getUserId();
await this.emailService.test(userId, receiver);
return this.ok({});
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询邮件列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询邮件列表" })
public async list() {
const userId = super.getUserId();
const res = await this.emailService.list(userId);
return this.ok(res);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加邮件" })
public async add(@Body('email') email) {
@Post("/add", { description: Constants.per.authOnly, summary: "添加邮件" })
public async add(@Body("email") email) {
const userId = super.getUserId();
await this.emailService.add(userId, email);
return this.ok({});
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除邮件" })
public async delete(@Body('email') email) {
@Post("/delete", { description: Constants.per.authOnly, summary: "删除邮件" })
public async delete(@Body("email") email) {
const userId = super.getUserId();
await this.emailService.delete(userId, email);
return this.ok({});
@@ -5,8 +5,8 @@ import { UserService } from "../../../modules/sys/authority/service/user-service
import { ApiTags } from "@midwayjs/swagger";
@Provide()
@Controller('/api/mine/passkey')
@ApiTags(['mine'])
@Controller("/api/mine/passkey")
@ApiTags(["mine"])
export class MinePasskeyController extends BaseController {
@Inject()
passkeyService: PasskeyService;
@@ -14,56 +14,43 @@ export class MinePasskeyController extends BaseController {
@Inject()
userService: UserService;
@Post('/generateRegistration', { description: Constants.per.authOnly, summary: "生成Passkey注册选项" })
@Post("/generateRegistration", { description: Constants.per.authOnly, summary: "生成Passkey注册选项" })
public async generateRegistration(
@Body(ALL)
body: any,
@RequestIP()
remoteIp: string
) {
const userId = this.getUserId()
const userId = this.getUserId();
const user = await this.userService.info(userId);
if (!user) {
throw new Error('用户不存在');
throw new Error("用户不存在");
}
const options = await this.passkeyService.generateRegistrationOptions(
userId,
user.username,
remoteIp,
this.ctx
);
const options = await this.passkeyService.generateRegistrationOptions(userId, user.username, remoteIp, this.ctx);
return this.ok({
...options,
});
}
@Post('/verifyRegistration', { description: Constants.per.authOnly, summary: "验证Passkey注册" })
@Post("/verifyRegistration", { description: Constants.per.authOnly, summary: "验证Passkey注册" })
public async verifyRegistration(
@Body(ALL)
body: any
) {
const userId = this.getUserId()
const userId = this.getUserId();
const response = body.response;
const challenge = body.challenge;
const deviceName = body.deviceName;
const result = await this.passkeyService.registerPasskey(
userId,
response,
challenge,
deviceName,
this.ctx
);
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
return this.ok(result);
}
@Post('/register', { description: Constants.per.authOnly, summary: "注册Passkey" })
@Post("/register", { description: Constants.per.authOnly, summary: "注册Passkey" })
public async registerPasskey(
@Body(ALL)
body: any
@@ -73,30 +60,23 @@ export class MinePasskeyController extends BaseController {
const deviceName = body.deviceName;
const challenge = body.challenge;
const result = await this.passkeyService.registerPasskey(
userId,
response,
challenge,
deviceName,
this.ctx
);
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
return this.ok(result);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询Passkey列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询Passkey列表" })
public async getPasskeys() {
const userId = this.getUserId();
const passkeys = await this.passkeyService.find({
select: ['id', 'deviceName', 'registeredAt', 'transports', 'passkeyId' ,'updateTime'],
select: ["id", "deviceName", "registeredAt", "transports", "passkeyId", "updateTime"],
where: { userId },
order: { registeredAt: 'DESC' },
order: { registeredAt: "DESC" },
});
return this.ok(passkeys);
}
@Post('/unbind', { description: Constants.per.authOnly, summary: "解绑Passkey" })
@Post("/unbind", { description: Constants.per.authOnly, summary: "解绑Passkey" })
public async unbindPasskey(@Body(ALL) body: any) {
const userId = this.getUserId();
const passkeyId = body.id;
@@ -106,11 +86,10 @@ export class MinePasskeyController extends BaseController {
});
if (!passkey) {
throw new Error('Passkey不存在');
throw new Error("Passkey不存在");
}
await this.passkeyService.delete([passkey.id]);
return this.ok({});
}
}
@@ -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();
}
}
@@ -10,8 +10,8 @@ import { ApiTags } from "@midwayjs/swagger";
/**
*/
@Provide()
@Controller('/api/user/settings')
@ApiTags(['mine'])
@Controller("/api/user/settings")
@ApiTags(["mine"])
export class UserSettingsController extends CrudController<UserSettingsService> {
@Inject()
service: UserSettingsService;
@@ -20,54 +20,54 @@ export class UserSettingsController extends CrudController<UserSettingsService>
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
async page(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
return super.page(body);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询用户设置列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询用户设置列表" })
async list(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
return super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加用户设置" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加用户设置" })
async add(@Body(ALL) bean) {
bean.userId = this.getUserId();
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新用户设置" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新用户设置" })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询用户设置详情" })
async info(@Query('id') id: number) {
@Post("/info", { description: Constants.per.authOnly, summary: "查询用户设置详情" })
async info(@Query("id") id: number) {
await this.service.checkUserId(id, this.getUserId());
return super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除用户设置" })
async delete(@Query('id') id: number) {
@Post("/delete", { description: Constants.per.authOnly, summary: "删除用户设置" })
async delete(@Query("id") id: number) {
await this.service.checkUserId(id, this.getUserId());
return super.delete(id);
}
@Post('/save', { description: Constants.per.authOnly, summary: "保存用户设置" })
@Post("/save", { description: Constants.per.authOnly, summary: "保存用户设置" })
async save(@Body(ALL) bean: UserSettingsEntity) {
bean.userId = this.getUserId();
await this.service.save(bean);
return this.ok({});
}
@Post('/get', { description: Constants.per.authOnly, summary: "获取用户设置" })
async get(@Query('key') key: string) {
const {projectId,userId} = await this.getProjectUserIdRead();
@Post("/get", { description: Constants.per.authOnly, summary: "获取用户设置" })
async get(@Query("key") key: string) {
const { projectId, userId } = await this.getProjectUserIdRead();
const entity = await this.service.getByKey(key, userId, projectId);
return this.ok(entity);
}
@@ -81,14 +81,13 @@ export class UserSettingsController extends CrudController<UserSettingsService>
@Post("/grant/save", { description: Constants.per.authOnly, summary: "保存授权设置" })
async grantSettingsSave(@Body(ALL) bean: UserGrantSetting) {
if (!isPlus()) {
throw new Error('本功能需要开通Certd专业版')
throw new Error("本功能需要开通Certd专业版");
}
const userId = this.getUserId();
const setting = new UserGrantSetting();
merge(setting, bean);
await this.service.saveSetting(userId,null, setting);
await this.service.saveSetting(userId, null, setting);
return this.ok({});
}
}