1.9+
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user