mirror of https://github.com/certd/certd
perf: 重置管理员密码同时可以清除管理员的2FA设置
parent
87853a2015
commit
1ece0915f1
|
@ -3,6 +3,7 @@ import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
|
||||||
import { CommonException } from '@certd/lib-server';
|
import { CommonException } from '@certd/lib-server';
|
||||||
import { UserService } from '../../modules/sys/authority/service/user-service.js';
|
import { UserService } from '../../modules/sys/authority/service/user-service.js';
|
||||||
import { logger } from '@certd/basic';
|
import { logger } from '@certd/basic';
|
||||||
|
import {UserSettingsService} from "../../modules/mine/service/user-settings-service.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置密码模式
|
* 重置密码模式
|
||||||
|
@ -13,6 +14,10 @@ import { logger } from '@certd/basic';
|
||||||
export class ResetPasswdMiddleware implements IWebMiddleware {
|
export class ResetPasswdMiddleware implements IWebMiddleware {
|
||||||
@Inject()
|
@Inject()
|
||||||
userService: UserService;
|
userService: UserService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
userSettingsService: UserSettingsService;
|
||||||
|
|
||||||
@Config('system.resetAdminPasswd')
|
@Config('system.resetAdminPasswd')
|
||||||
private resetAdminPasswd: boolean;
|
private resetAdminPasswd: boolean;
|
||||||
resolve() {
|
resolve() {
|
||||||
|
@ -31,8 +36,12 @@ export class ResetPasswdMiddleware implements IWebMiddleware {
|
||||||
const newPasswd = '123456';
|
const newPasswd = '123456';
|
||||||
await this.userService.resetPassword(1, newPasswd);
|
await this.userService.resetPassword(1, newPasswd);
|
||||||
await this.userService.updateStatus(1, 1);
|
await this.userService.updateStatus(1, 1);
|
||||||
|
await this.userSettingsService.deleteWhere({
|
||||||
|
userId: 1,
|
||||||
|
key:"user.two.factor"
|
||||||
|
})
|
||||||
const user = await this.userService.info(1);
|
const user = await this.userService.info(1);
|
||||||
logger.info(`重置1号管理员用户的密码完成,用户名:${user.username},新密码:${newPasswd}`);
|
logger.info(`重置1号管理员用户的密码完成,2FA设置已删除,用户名:${user.username},新密码:${newPasswd},请在登录进去之后尽快修改密码`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue