mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
perf: 新增找回密码功能 @nicheng-he
* feat 找回密码 * 1.发送邮件时修改模版 2.重置成功时清除登陆错误次数 * 增加自助找回密码控制 * 补充接口自助找回判断
This commit is contained in:
@@ -15,6 +15,7 @@ import { DbAdapter } from '../../../db/index.js';
|
||||
import { simpleNanoId, utils } from '@certd/basic';
|
||||
|
||||
export type RegisterType = 'username' | 'mobile' | 'email';
|
||||
export type ForgotPasswordType = 'mobile' | 'email';
|
||||
|
||||
export const AdminRoleId = 1
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ export const AdminRoleId = 1
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
|
||||
@InjectEntityModel(UserEntity)
|
||||
repository: Repository<UserEntity>;
|
||||
@Inject()
|
||||
@@ -229,6 +230,29 @@ export class UserService extends BaseService<UserEntity> {
|
||||
return newUser;
|
||||
}
|
||||
|
||||
async forgotPassword(
|
||||
data: {
|
||||
type: ForgotPasswordType; input?: string, phoneCode?: string,
|
||||
randomStr: string, imgCode:string, validateCode: string,
|
||||
password: string, confirmPassword: string,
|
||||
}
|
||||
) {
|
||||
if(!data.type) {
|
||||
throw new CommonException('找回类型不能为空');
|
||||
}
|
||||
if(data.password !== data.confirmPassword) {
|
||||
throw new CommonException('两次输入的密码不一致');
|
||||
}
|
||||
const user = await this.findOne([{ [data.type]: data.input }]);
|
||||
console.log('user', user)
|
||||
if(!user) {
|
||||
throw new CommonException('用户不存在');
|
||||
// return;
|
||||
}
|
||||
await this.resetPassword(user.id, data.password)
|
||||
return user.username;
|
||||
}
|
||||
|
||||
async changePassword(userId: any, form: any) {
|
||||
const user = await this.info(userId);
|
||||
const passwordChecked = await this.checkPassword(form.password, user.password, user.passwordVersion);
|
||||
|
||||
Reference in New Issue
Block a user