mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
perf: 新增找回密码功能 @nicheng-he
* feat 找回密码 * 1.发送邮件时修改模版 2.重置成功时清除登陆错误次数 * 增加自助找回密码控制 * 补充接口自助找回判断
This commit is contained in:
@@ -27,6 +27,9 @@ export class EmailCodeReq {
|
||||
|
||||
@Rule(RuleType.string().required().max(4))
|
||||
imgCode: string;
|
||||
|
||||
@Rule(RuleType.string())
|
||||
verificationType: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,8 +58,20 @@ export class BasicController extends BaseController {
|
||||
@Body(ALL)
|
||||
body: EmailCodeReq
|
||||
) {
|
||||
const opts = {
|
||||
verificationType: body.verificationType,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
duration: undefined,
|
||||
};
|
||||
if(body?.verificationType === 'forgotPassword') {
|
||||
opts.title = '找回密码';
|
||||
opts.content = '验证码:${code}。您正在找回密码,请输入验证码并完成操作。如非本人操作请忽略';
|
||||
opts.duration = 3;
|
||||
}
|
||||
|
||||
await this.codeService.checkCaptcha(body.randomStr, body.imgCode);
|
||||
await this.codeService.sendEmailCode(body.email, body.randomStr);
|
||||
await this.codeService.sendEmailCode(body.email, body.randomStr, opts);
|
||||
// 设置缓存内容
|
||||
return this.ok(null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, CommonException, Constants, SysSettingsService } from "@certd/lib-server";
|
||||
import { CodeService } from '../../../modules/basic/service/code-service.js';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api')
|
||||
export class LoginController extends BaseController {
|
||||
@Inject()
|
||||
loginService: LoginService;
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
@Inject()
|
||||
codeService: CodeService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
@Post('/forgotPassword', { summary: Constants.per.guest })
|
||||
public async forgotPassword(
|
||||
@Body(ALL)
|
||||
body: any,
|
||||
) {
|
||||
const sysSettings = await this.sysSettingsService.getPublicSettings();
|
||||
if(!sysSettings.selfServicePasswordRetrievalEnabled) {
|
||||
throw new CommonException('暂未开启自助找回');
|
||||
}
|
||||
|
||||
if(body.type === 'email') {
|
||||
this.codeService.checkEmailCode({
|
||||
verificationType: 'forgotPassword',
|
||||
email: body.input,
|
||||
randomStr: body.randomStr,
|
||||
validateCode: body.validateCode,
|
||||
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,
|
||||
throwError: true,
|
||||
});
|
||||
} else {
|
||||
throw new CommonException('暂不支持的找回类型,请联系管理员找回');
|
||||
}
|
||||
const username = await this.userService.forgotPassword(body);
|
||||
username && this.loginService.clearCacheOnSuccess(username)
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user