|
|
@@ -8,7 +8,8 @@ import {
|
|
|
UpdateGuestBody,
|
|
|
MemberLoginBody,
|
|
|
ResetPasswordBody,
|
|
|
- RegisterBody
|
|
|
+ RegisterBody,
|
|
|
+ UpdateProfileBody
|
|
|
} from '../dto/member.dto'
|
|
|
import { VipLevel, MemberStatus } from '../entities/member.entity'
|
|
|
import { UserService } from '../services/user.service'
|
|
|
@@ -206,8 +207,8 @@ export class MemberController {
|
|
|
async resetPassword(request: FastifyRequest<{ Body: ResetPasswordBody }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
const { password } = request.body
|
|
|
- if (password.length < 8 || !/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/.test(password)) {
|
|
|
- return reply.code(400).send({ message: '密码长度必须至少8位,包含大小写字母和数字' })
|
|
|
+ if (password.length < 6) {
|
|
|
+ return reply.code(400).send({ message: '密码长度必须至少8位' })
|
|
|
}
|
|
|
|
|
|
await this.userService.resetPassword(request.user.id, password)
|
|
|
@@ -217,6 +218,36 @@ export class MemberController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async updateProfile(request: FastifyRequest<{ Body: UpdateProfileBody }>, reply: FastifyReply) {
|
|
|
+ try {
|
|
|
+ const { name, email } = request.body
|
|
|
+
|
|
|
+ // 验证必填字段
|
|
|
+ if (!name) {
|
|
|
+ return reply.code(400).send({ message: '用户名为必填字段' })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证用户名格式
|
|
|
+ if (name.length < 3 || name.length > 20) {
|
|
|
+ return reply.code(400).send({ message: '用户名长度必须在3-20个字符之间' })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证邮箱格式
|
|
|
+ if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
|
+ return reply.code(400).send({ message: '邮箱格式不正确' })
|
|
|
+ }
|
|
|
+
|
|
|
+ await this.memberService.updateProfile(request.user.id, name, email)
|
|
|
+ return reply.send({ message: '个人信息更新成功' })
|
|
|
+ } catch (error) {
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '更新个人信息失败'
|
|
|
+ if (errorMessage.includes('已被使用')) {
|
|
|
+ return reply.code(400).send({ message: errorMessage })
|
|
|
+ }
|
|
|
+ return reply.code(500).send({ message: '更新个人信息失败' })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async updateVipLevel(
|
|
|
request: FastifyRequest<{
|
|
|
Params: { id: string }
|