mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
perf: 重置管理员密码同时启用管理员账户,避免之前禁用了,重置密码还是登录不进去
This commit is contained in:
@@ -30,6 +30,7 @@ export class ResetPasswdMiddleware implements IWebMiddleware {
|
||||
logger.info('开始重置1号管理员用户的密码');
|
||||
const newPasswd = '123456';
|
||||
await this.userService.resetPassword(1, newPasswd);
|
||||
await this.userService.updateStatus(1, 1);
|
||||
logger.info(`重置1号管理员用户的密码完成,新密码为:${newPasswd}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +198,9 @@ export class UserService extends BaseService<UserEntity> {
|
||||
}
|
||||
|
||||
async resetPassword(userId: any, newPasswd: string) {
|
||||
if (!userId) {
|
||||
throw new CommonException('userId不能为空');
|
||||
}
|
||||
const param = {
|
||||
id: userId,
|
||||
password: newPasswd,
|
||||
@@ -210,15 +213,19 @@ export class UserService extends BaseService<UserEntity> {
|
||||
ids = ids.split(',');
|
||||
ids = ids.map(id => parseInt(id));
|
||||
}
|
||||
if (ids instanceof Array) {
|
||||
if (ids.includes(1)) {
|
||||
throw new CommonException('不能删除管理员');
|
||||
}
|
||||
if (ids.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (ids.includes(1)) {
|
||||
throw new CommonException('不能删除管理员');
|
||||
}
|
||||
await super.delete(ids);
|
||||
}
|
||||
|
||||
async isAdmin(userId: any) {
|
||||
if (!userId) {
|
||||
throw new CommonException('userId不能为空');
|
||||
}
|
||||
const userRoles = await this.userRoleService.find({
|
||||
where: {
|
||||
userId,
|
||||
@@ -229,4 +236,13 @@ export class UserService extends BaseService<UserEntity> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
async updateStatus(id: number, status: number) {
|
||||
if (!id) {
|
||||
throw new CommonException('userId不能为空');
|
||||
}
|
||||
await this.repository.update(id, {
|
||||
status,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user