2024-10-05 01:46:25 +08:00
|
|
|
import { BaseController, Constants } from '@certd/lib-server';
|
2026-03-12 18:11:02 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
|
|
|
|
import { PasskeyService } from '../../../modules/login/service/passkey-service.js';
|
2025-01-15 01:05:34 +08:00
|
|
|
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
2026-03-12 18:11:02 +08:00
|
|
|
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
2026-03-15 14:01:34 +08:00
|
|
|
import { ApiTags } from '@midwayjs/swagger';
|
2023-06-28 23:15:37 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/mine')
|
2026-03-15 14:01:34 +08:00
|
|
|
@ApiTags(['mine'])
|
2023-06-28 23:15:37 +08:00
|
|
|
export class MineController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
userService: UserService;
|
2026-03-12 18:11:02 +08:00
|
|
|
|
2024-10-03 01:29:12 +08:00
|
|
|
@Inject()
|
|
|
|
|
roleService: RoleService;
|
2026-03-12 18:11:02 +08:00
|
|
|
|
|
|
|
|
@Inject()
|
|
|
|
|
passkeyService: PasskeyService;
|
|
|
|
|
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/info', { description: Constants.per.authOnly, summary: "查询用户信息" })
|
2023-06-28 23:15:37 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/changePassword', { description: Constants.per.authOnly, summary: "修改密码" })
|
2023-06-28 23:15:37 +08:00
|
|
|
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
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/updateProfile', { description: Constants.per.authOnly, summary: "更新用户资料" })
|
2025-07-01 16:30:07 +08:00
|
|
|
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
|
|
|
}
|