2024-07-15 00:30:33 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
2024-10-05 01:46:25 +08:00
|
|
|
import { BaseController, Constants } from '@certd/lib-server';
|
2025-01-15 01:05:34 +08:00
|
|
|
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
|
|
|
|
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
2023-06-28 23:15:37 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/mine')
|
|
|
|
|
export class MineController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
userService: UserService;
|
2024-10-03 01:29:12 +08:00
|
|
|
@Inject()
|
|
|
|
|
roleService: RoleService;
|
2023-06-28 23:15:37 +08:00
|
|
|
@Post('/info', { summary: Constants.per.authOnly })
|
|
|
|
|
public async info() {
|
|
|
|
|
const userId = this.getUserId();
|
|
|
|
|
const user = await this.userService.info(userId);
|
2024-11-30 22:35:26 +08:00
|
|
|
const isWeak = await this.userService.checkPassword('123456', user.password, user.passwordVersion);
|
|
|
|
|
if (isWeak) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
user.isWeak = true;
|
|
|
|
|
}
|
2024-10-03 01:29:12 +08:00
|
|
|
user.roleIds = await this.roleService.getRoleIdsByUserId(userId);
|
2023-06-28 23:15:37 +08:00
|
|
|
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({});
|
|
|
|
|
}
|
2025-07-01 16:30:07 +08:00
|
|
|
|
|
|
|
|
@Post('/updateProfile', { summary: Constants.per.authOnly })
|
|
|
|
|
public async updateProfile(@Body(ALL) body: any) {
|
|
|
|
|
const userId = this.getUserId();
|
|
|
|
|
|
|
|
|
|
await this.userService.updateProfile(userId, {
|
|
|
|
|
avatar: body.avatar,
|
|
|
|
|
nickName: body.nickName,
|
|
|
|
|
});
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2023-06-28 23:15:37 +08:00
|
|
|
}
|