mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
chore: plus
This commit is contained in:
@@ -2,6 +2,7 @@ import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
|
||||
import {BaseController, SysSafeSetting} from '@certd/lib-server';
|
||||
import {cloneDeep} from 'lodash-es';
|
||||
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" })
|
||||
async safeSave(@Body(ALL) body: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通专业版')
|
||||
}
|
||||
await this.safeService.saveSafeSetting(body);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -27,6 +28,9 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
|
||||
@Post("/save", { summary: Constants.per.authOnly })
|
||||
async save(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通专业版')
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
const setting = new UserTwoFactorSetting();
|
||||
merge(setting, bean);
|
||||
@@ -50,6 +54,9 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
|
||||
@Post("/authenticator/save", { summary: Constants.per.authOnly })
|
||||
async authenticatorSave(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通专业版')
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
await this.twoFactorService.saveAuthenticator({
|
||||
userId,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Config, Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
|
||||
import {UserService} from '../../sys/authority/service/user-service.js';
|
||||
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 {UserEntity} from '../../sys/authority/entity/user.js';
|
||||
import {SysSettingsService} from '@certd/lib-server';
|
||||
@@ -9,8 +9,9 @@ import {SysPrivateSettings} from '@certd/lib-server';
|
||||
import {cache, utils} from '@certd/basic';
|
||||
import {LoginErrorException} from '@certd/lib-server/dist/basic/exception/login-error-exception.js';
|
||||
import {CodeService} from '../../basic/service/code-service.js';
|
||||
import { TwoFactorService } from "../../mine/service/two-factor-service.js";
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
import {TwoFactorService} from "../../mine/service/two-factor-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);
|
||||
}
|
||||
|
||||
async checkTwoFactorEnabled(userId:number) {
|
||||
async checkTwoFactorEnabled(userId: number) {
|
||||
//检查是否开启多重认证
|
||||
if (!isPlus()) {
|
||||
return true
|
||||
}
|
||||
|
||||
const twoFactorSetting = await this.twoFactorService.getSetting(userId)
|
||||
|
||||
const authenticatorSetting = twoFactorSetting.authenticator
|
||||
if (authenticatorSetting.enabled){
|
||||
if (authenticatorSetting.enabled) {
|
||||
//要检查
|
||||
const randomKey = utils.id.simpleNanoId(12)
|
||||
cache.set(`login_2fa_code:${randomKey}`, userId, {
|
||||
@@ -161,9 +165,13 @@ export class LoginService {
|
||||
|
||||
}
|
||||
|
||||
async loginByTwoFactor(req: { loginCode: string; verifyCode: string }){
|
||||
const userId = cache.get(`login_2fa_code:${req.loginCode}`)
|
||||
if (!userId){
|
||||
async loginByTwoFactor(req: { loginCode: string; verifyCode: string }) {
|
||||
//检查是否开启多重认证
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通专业版')
|
||||
}
|
||||
const userId = cache.get(`login_2fa_code:${req.loginCode}`)
|
||||
if (!userId) {
|
||||
throw new AuthException('登录状态已失效,请重新登录')
|
||||
}
|
||||
await this.twoFactorService.verifyAuthenticatorCode(userId, req.verifyCode)
|
||||
@@ -180,7 +188,6 @@ export class LoginService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
* @param user 用户对象
|
||||
|
||||
Reference in New Issue
Block a user