mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
perf: 登录注册、找回密码都支持极验验证码和图片验证码
This commit is contained in:
@@ -29,25 +29,23 @@ export class LoginController extends BaseController {
|
||||
throw new CommonException('暂未开启自助找回');
|
||||
}
|
||||
// 找回密码的验证码允许错误次数
|
||||
const errorNum = 5;
|
||||
const maxErrorCount = 5;
|
||||
|
||||
if(body.type === 'email') {
|
||||
this.codeService.checkEmailCode({
|
||||
verificationType: 'forgotPassword',
|
||||
email: body.input,
|
||||
randomStr: body.randomStr,
|
||||
validateCode: body.validateCode,
|
||||
errorNum,
|
||||
maxErrorCount: maxErrorCount,
|
||||
throwError: true,
|
||||
});
|
||||
} else if(body.type === 'mobile') {
|
||||
await this.codeService.checkSmsCode({
|
||||
verificationType: 'forgotPassword',
|
||||
mobile: body.input,
|
||||
randomStr: body.randomStr,
|
||||
phoneCode: body.phoneCode,
|
||||
smsCode: body.validateCode,
|
||||
errorNum,
|
||||
maxErrorCount: maxErrorCount,
|
||||
throwError: true,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -3,8 +3,7 @@ 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";
|
||||
import { CaptchaService } from "../../../modules/basic/service/captcha-service.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -21,12 +20,18 @@ export class LoginController extends BaseController {
|
||||
@Inject()
|
||||
addonService: AddonService;
|
||||
|
||||
@Inject()
|
||||
captchaService: CaptchaService;
|
||||
|
||||
@Post('/login', { summary: Constants.per.guest })
|
||||
public async login(
|
||||
@Body(ALL)
|
||||
body: any
|
||||
) {
|
||||
await this.loginService.doCaptchaValidate({form:body.captcha})
|
||||
const settings = await this.sysSettingsService.getPublicSettings()
|
||||
if (settings.captchaEnabled === true) {
|
||||
await this.captchaService.doValidate({form:body.captcha,must:false,captchaAddonId:settings.captchaAddonId})
|
||||
}
|
||||
const token = await this.loginService.loginByPassword(body);
|
||||
this.writeTokenCookie(token);
|
||||
return this.ok(token);
|
||||
@@ -83,24 +88,4 @@ 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({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ export type RegisterReq = {
|
||||
phoneCode?: string;
|
||||
|
||||
validateCode: string;
|
||||
imgCode: string;
|
||||
randomStr: string;
|
||||
captcha:any;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -52,7 +51,7 @@ export class RegisterController extends BaseController {
|
||||
throw new Error('用户名不能为空');
|
||||
}
|
||||
|
||||
await this.codeService.checkCaptcha(body.randomStr, body.imgCode);
|
||||
await this.codeService.checkCaptcha(body.captcha);
|
||||
const newUser = await this.userService.register(body.type, {
|
||||
username: body.username,
|
||||
password: body.password,
|
||||
@@ -68,7 +67,6 @@ export class RegisterController extends BaseController {
|
||||
mobile: body.mobile,
|
||||
phoneCode: body.phoneCode,
|
||||
smsCode: body.validateCode,
|
||||
randomStr: body.randomStr,
|
||||
throwError: true,
|
||||
});
|
||||
const newUser = await this.userService.register(body.type, {
|
||||
@@ -85,7 +83,6 @@ export class RegisterController extends BaseController {
|
||||
checkPlus();
|
||||
this.codeService.checkEmailCode({
|
||||
email: body.email,
|
||||
randomStr: body.randomStr,
|
||||
validateCode: body.validateCode,
|
||||
throwError: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user