mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
chore: change password
This commit is contained in:
@@ -142,4 +142,17 @@ export class UserService extends BaseService<UserEntity> {
|
||||
delete newUser.password;
|
||||
return newUser;
|
||||
}
|
||||
|
||||
async changePassword(userId: any, form: any) {
|
||||
const user = await this.info(userId);
|
||||
if (!this.checkPassword(form.password, user.password)) {
|
||||
throw new CommonException('原密码错误');
|
||||
}
|
||||
const param = {
|
||||
id: userId,
|
||||
password: form.newPassword,
|
||||
};
|
||||
|
||||
await this.update(param);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/mine')
|
||||
export class MineController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
public async info() {
|
||||
const userId = this.getUserId();
|
||||
const user = await this.userService.info(userId);
|
||||
delete user.password;
|
||||
return this.ok(user);
|
||||
}
|
||||
|
||||
@Post('/changePassword', { summary: Constants.per.authOnly })
|
||||
public async changePassword(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.userService.changePassword(userId, body);
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user