This commit is contained in:
2026-06-15 19:14:13 +08:00
parent c9fc87cd89
commit 4167714149
6 changed files with 191 additions and 31 deletions
+10
View File
@@ -61,6 +61,16 @@ class UserService:
user.password_hash = hash_password(new_password)
user.updated_at = datetime.utcnow()
async def delete_account(self, user_id: str, password: str):
"""注销账号:验证密码后删除用户(FK CASCADE 级联清理相关数据)"""
from sqlalchemy import delete
user = await self.get_by_id(user_id)
if not user:
raise ValueError("用户不存在")
if not verify_password(password, user.password_hash):
raise ValueError("密码错误,无法注销")
await self.db.execute(delete(User).where(User.id == user_id))
async def change_email(self, user_id: str, new_email: str, password: str):
"""更换绑定邮箱"""
user = await self.get_by_id(user_id)