perf: 登录支持极验验证码

This commit is contained in:
xiaojunnuo
2025-09-11 23:47:05 +08:00
parent 65f34f1d31
commit 370db62bf0
22 changed files with 552 additions and 129 deletions
@@ -1,18 +1,17 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import {
AccessGetter,
AddonDefine,
AddonRequestHandleReq,
AddonService,
Constants,
CrudController,
newAddon,
ValidateException
} from "@certd/lib-server";
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { checkPlus } from '@certd/plus-core';
import { AddonService } from "@certd/lib-server";
import { AddonDefine } from "@certd/lib-server";
import { AccessRequestHandleReq, newAccess } from "@certd/pipeline";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { checkPlus } from "@certd/plus-core";
import { http, logger, utils } from "@certd/basic";
/**
* Addon
*/
@@ -1,8 +1,10 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { LoginService } from '../../../modules/login/service/login-service.js';
import { BaseController, Constants, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
import { CodeService } from '../../../modules/basic/service/code-service.js';
import { checkComm } from '@certd/plus-core';
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
import { LoginService } from "../../../modules/login/service/login-service.js";
import { AddonService, BaseController, Constants, SysPublicSettings, SysSettingsService } from "@certd/lib-server";
import { CodeService } from "../../../modules/basic/service/code-service.js";
import { checkComm } from "@certd/plus-core";
import { logger } from "@certd/basic";
import { ICaptchaAddon } from "../../../plugins/plugin-captcha/api.js";
/**
*/
@@ -16,14 +18,16 @@ export class LoginController extends BaseController {
@Inject()
sysSettingsService: SysSettingsService;
@Inject()
addonService: AddonService;
@Post('/login', { summary: Constants.per.guest })
public async login(
@Body(ALL)
user: any
body: any
) {
await this.loginService.doCaptchaValidate({form:user})
const token = await this.loginService.loginByPassword(user);
await this.loginService.doCaptchaValidate({form:body.captcha})
const token = await this.loginService.loginByPassword(body);
this.writeTokenCookie(token);
return this.ok(token);
}
@@ -79,4 +83,24 @@ export class LoginController extends BaseController {
});
return this.ok();
}
@Post('/captcha/getParams', { summary: Constants.per.guest })
async getCaptchaParams() {
const settings = await this.sysSettingsService.getPublicSettings()
if (settings.captchaEnabled) {
const addonId = settings.captchaAddonId;
const addon:ICaptchaAddon = await this.addonService.getAddonById(addonId,true,0)
if (!addon) {
logger.warn('验证码插件还未配置')
return this.ok({});
}
const params = await addon.getClientParams()
return this.ok(params);
}
return this.ok({});
}
}