chore: plus

pull/409/head
xiaojunnuo 2025-04-17 13:41:08 +08:00
parent d5d54d4d3b
commit 8e50e5dee3
6 changed files with 55 additions and 29 deletions

View File

@ -7,11 +7,13 @@
<a-form :model="formState" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off"> <a-form :model="formState" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off">
<a-form-item label="OTP多重验证登录" :name="['authenticator', 'enabled']"> <a-form-item label="OTP多重验证登录" :name="['authenticator', 'enabled']">
<div class="flex mt-5"> <div class="flex mt-5">
<a-switch v-model:checked="formState.authenticator.enabled" @change="onAuthenticatorEnabledChanged" /> <a-switch v-model:checked="formState.authenticator.enabled" :disabled="!settingsStore.isPlus" @change="onAuthenticatorEnabledChanged" />
<a-button v-if="formState.authenticator.enabled && formState.authenticator.verified" :disabled="authenticatorOpenRef" size="small" class="ml-2" type="primary" @click="authenticatorForm.open = true"> <a-button v-if="formState.authenticator.enabled && formState.authenticator.verified" :disabled="authenticatorOpenRef" size="small" class="ml-5" type="primary" @click="authenticatorForm.open = true">
重新绑定 重新绑定
</a-button> </a-button>
<vip-button class="ml-5" mode="button"></vip-button>
</div> </div>
<div class="helper">是否开启多重验证登录</div> <div class="helper">是否开启多重验证登录</div>
@ -45,7 +47,8 @@ import * as api from "./api";
import { UserTwoFactorSetting } from "./api"; import { UserTwoFactorSetting } from "./api";
import { Modal, notification } from "ant-design-vue"; import { Modal, notification } from "ant-design-vue";
import { merge } from "lodash-es"; import { merge } from "lodash-es";
import { useSettingStore } from "/@/store/settings";
const settingsStore = useSettingStore();
defineOptions({ defineOptions({
name: "UserSecurity", name: "UserSecurity",
}); });
@ -92,7 +95,7 @@ const doAuthenticatorSave = async (form: any) => {
authenticatorForm.open = false; authenticatorForm.open = false;
}; };
function onAuthenticatorEnabledChanged(value) { function onAuthenticatorEnabledChanged(value: any) {
if (!value) { if (!value) {
// //
if (formState.authenticator.verified) { if (formState.authenticator.verified) {

View File

@ -66,34 +66,34 @@ import { useSettingStore } from "/@/store/settings";
import { notification } from "ant-design-vue"; import { notification } from "ant-design-vue";
defineOptions({ defineOptions({
name: "SettingRegister" name: "SettingRegister",
}); });
const testMobile = ref(""); const testMobile = ref("");
async function testSendSms() { async function testSendSms() {
if (!testMobile.value) { if (!testMobile.value) {
notification.error({ notification.error({
message: "请输入测试手机号" message: "请输入测试手机号",
}); });
return; return;
} }
await api.TestSms({ await api.TestSms({
mobile: testMobile.value mobile: testMobile.value,
}); });
notification.success({ notification.success({
message: "发送成功" message: "发送成功",
}); });
} }
const formState = reactive<Partial<SysSettings>>({ const formState = reactive<Partial<SysSettings>>({
public: { public: {
registerEnabled: false registerEnabled: false,
}, },
private: { private: {
sms: { sms: {
type: "aliyun", type: "aliyun",
config: {} config: {},
} },
} },
}); });
const rules = { const rules = {
@ -103,13 +103,13 @@ const rules = {
return Promise.reject("密码登录和手机号登录至少开启一个"); return Promise.reject("密码登录和手机号登录至少开启一个");
} }
return Promise.resolve(); return Promise.resolve();
} },
}, },
required: { required: {
required: true, required: true,
trigger: "change", trigger: "change",
message: "此项必填" message: "此项必填",
} },
}; };
async function smsTypeChange(value: string) { async function smsTypeChange(value: string) {
@ -124,13 +124,13 @@ async function loadTypeDefine(type: string) {
const define: any = await api.GetSmsTypeDefine(type); const define: any = await api.GetSmsTypeDefine(type);
const keys = Object.keys(define.input); const keys = Object.keys(define.input);
const inputs: any = {}; const inputs: any = {};
keys.forEach((key) => { keys.forEach(key => {
const value = define.input[key]; const value = define.input[key];
value.simpleKey = key; value.simpleKey = key;
value.key = "private.sms.config." + key; value.key = "private.sms.config." + key;
if (!value.component) { if (!value.component) {
value.component = { value.component = {
name: "a-input" name: "a-input",
}; };
} }
if (!value.component.name) { if (!value.component.name) {
@ -165,7 +165,7 @@ const onFinish = async (form: any) => {
await api.SysSettingsSave(form); await api.SysSettingsSave(form);
await settingsStore.loadSysSettings(); await settingsStore.loadSysSettings();
notification.success({ notification.success({
message: "保存成功" message: "保存成功",
}); });
} finally { } finally {
saveLoading.value = false; saveLoading.value = false;

View File

@ -3,7 +3,11 @@
<a-form ref="formRef" :model="formState" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off"> <a-form ref="formRef" :model="formState" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off">
<h2>站点隐藏</h2> <h2>站点隐藏</h2>
<a-form-item label="启用站点隐藏" :name="['hidden', 'enabled']" :required="true"> <a-form-item label="启用站点隐藏" :name="['hidden', 'enabled']" :required="true">
<a-switch v-model:checked="formState.hidden.enabled" /> <div class="flex">
<a-switch v-model:checked="formState.hidden.enabled" :disabled="!settingsStore.isPlus" />
<vip-button class="ml-5" mode="button"></vip-button>
</div>
<div class="helper"> <div class="helper">
可以在平时关闭站点的可访问性需要时再打开增强站点安全性 可以在平时关闭站点的可访问性需要时再打开增强站点安全性
<a href="https://certd.docmirror.cn/guide/feature/safe/hidden" class="flex items-center" target="_blank"> <a href="https://certd.docmirror.cn/guide/feature/safe/hidden" class="flex items-center" target="_blank">
@ -52,10 +56,11 @@ import { merge } from "lodash-es";
import { Modal, notification } from "ant-design-vue"; import { Modal, notification } from "ant-design-vue";
import { request } from "/@/api/service"; import { request } from "/@/api/service";
import { util, utils } from "/@/utils"; import { util, utils } from "/@/utils";
import { useSettingStore } from "/@/store/settings";
defineOptions({ defineOptions({
name: "SettingSafe", name: "SettingSafe",
}); });
const settingsStore = useSettingStore();
const api = { const api = {
async SettingGet() { async SettingGet() {
return await request({ return await request({

View File

@ -2,6 +2,7 @@ import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
import {BaseController, SysSafeSetting} from '@certd/lib-server'; import {BaseController, SysSafeSetting} from '@certd/lib-server';
import {cloneDeep} from 'lodash-es'; import {cloneDeep} from 'lodash-es';
import {SafeService} from "../../../modules/sys/settings/safe-service.js"; import {SafeService} from "../../../modules/sys/settings/safe-service.js";
import {isPlus} from "@certd/plus-core";
/** /**
@ -24,6 +25,9 @@ export class SysSettingsController extends BaseController {
@Post("/save", { summary: "sys:settings:edit" }) @Post("/save", { summary: "sys:settings:edit" })
async safeSave(@Body(ALL) body: any) { async safeSave(@Body(ALL) body: any) {
if (!isPlus()) {
throw new Error('本功能需要开通专业版')
}
await this.safeService.saveSafeSetting(body); await this.safeService.saveSafeSetting(body);
return this.ok({}); return this.ok({});
} }

View File

@ -4,6 +4,7 @@ import { UserSettingsService } from "../../../modules/mine/service/user-settings
import { UserTwoFactorSetting } from "../../../modules/mine/service/models.js"; import { UserTwoFactorSetting } from "../../../modules/mine/service/models.js";
import { merge } from "lodash-es"; import { merge } from "lodash-es";
import { TwoFactorService } from "../../../modules/mine/service/two-factor-service.js"; import { TwoFactorService } from "../../../modules/mine/service/two-factor-service.js";
import {isPlus} from "@certd/plus-core";
/** /**
*/ */
@ -27,6 +28,9 @@ export class UserTwoFactorSettingController extends BaseController {
@Post("/save", { summary: Constants.per.authOnly }) @Post("/save", { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: any) { async save(@Body(ALL) bean: any) {
if (!isPlus()) {
throw new Error('本功能需要开通专业版')
}
const userId = this.getUserId(); const userId = this.getUserId();
const setting = new UserTwoFactorSetting(); const setting = new UserTwoFactorSetting();
merge(setting, bean); merge(setting, bean);
@ -50,6 +54,9 @@ export class UserTwoFactorSettingController extends BaseController {
@Post("/authenticator/save", { summary: Constants.per.authOnly }) @Post("/authenticator/save", { summary: Constants.per.authOnly })
async authenticatorSave(@Body(ALL) bean: any) { async authenticatorSave(@Body(ALL) bean: any) {
if (!isPlus()) {
throw new Error('本功能需要开通专业版')
}
const userId = this.getUserId(); const userId = this.getUserId();
await this.twoFactorService.saveAuthenticator({ await this.twoFactorService.saveAuthenticator({
userId, userId,

View File

@ -1,7 +1,7 @@
import {Config, Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core'; import {Config, Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
import {UserService} from '../../sys/authority/service/user-service.js'; import {UserService} from '../../sys/authority/service/user-service.js';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { AuthException, CommonException, Need2FAException } from "@certd/lib-server"; import {AuthException, CommonException, Need2FAException} from "@certd/lib-server";
import {RoleService} from '../../sys/authority/service/role-service.js'; import {RoleService} from '../../sys/authority/service/role-service.js';
import {UserEntity} from '../../sys/authority/entity/user.js'; import {UserEntity} from '../../sys/authority/entity/user.js';
import {SysSettingsService} from '@certd/lib-server'; import {SysSettingsService} from '@certd/lib-server';
@ -9,8 +9,9 @@ import {SysPrivateSettings} from '@certd/lib-server';
import {cache, utils} from '@certd/basic'; import {cache, utils} from '@certd/basic';
import {LoginErrorException} from '@certd/lib-server/dist/basic/exception/login-error-exception.js'; import {LoginErrorException} from '@certd/lib-server/dist/basic/exception/login-error-exception.js';
import {CodeService} from '../../basic/service/code-service.js'; import {CodeService} from '../../basic/service/code-service.js';
import { TwoFactorService } from "../../mine/service/two-factor-service.js"; import {TwoFactorService} from "../../mine/service/two-factor-service.js";
import { UserSettingsService } from '../../mine/service/user-settings-service.js'; import {UserSettingsService} from '../../mine/service/user-settings-service.js';
import {isPlus} from "@certd/plus-core";
/** /**
* *
@ -144,13 +145,16 @@ export class LoginService {
return this.onLoginSuccess(info); return this.onLoginSuccess(info);
} }
async checkTwoFactorEnabled(userId:number) { async checkTwoFactorEnabled(userId: number) {
//检查是否开启多重认证 //检查是否开启多重认证
if (!isPlus()) {
return true
}
const twoFactorSetting = await this.twoFactorService.getSetting(userId) const twoFactorSetting = await this.twoFactorService.getSetting(userId)
const authenticatorSetting = twoFactorSetting.authenticator const authenticatorSetting = twoFactorSetting.authenticator
if (authenticatorSetting.enabled){ if (authenticatorSetting.enabled) {
//要检查 //要检查
const randomKey = utils.id.simpleNanoId(12) const randomKey = utils.id.simpleNanoId(12)
cache.set(`login_2fa_code:${randomKey}`, userId, { cache.set(`login_2fa_code:${randomKey}`, userId, {
@ -161,9 +165,13 @@ export class LoginService {
} }
async loginByTwoFactor(req: { loginCode: string; verifyCode: string }){ async loginByTwoFactor(req: { loginCode: string; verifyCode: string }) {
//检查是否开启多重认证
if (!isPlus()) {
throw new Error('本功能需要开通专业版')
}
const userId = cache.get(`login_2fa_code:${req.loginCode}`) const userId = cache.get(`login_2fa_code:${req.loginCode}`)
if (!userId){ if (!userId) {
throw new AuthException('登录状态已失效,请重新登录') throw new AuthException('登录状态已失效,请重新登录')
} }
await this.twoFactorService.verifyAuthenticatorCode(userId, req.verifyCode) await this.twoFactorService.verifyAuthenticatorCode(userId, req.verifyCode)
@ -180,7 +188,6 @@ export class LoginService {
} }
/** /**
* token * token
* @param user * @param user