2025-12-04 10:04:21 +08:00

40 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# app/models/domain/users.py
from typing import List, Optional
from pydantic import Field
from app.models.common import DateTimeModelMixin, IDModelMixin
from app.models.domain.rwmodel import RWModel
from app.services import security
class User(RWModel):
"""
公开用户信息会被用于文章作者、Profile 等场景)。
新增 email_verified 字段,便于前端展示与登录后逻辑判断。
"""
username: str
email: str
bio: str = ""
image: Optional[str] = None
phone: Optional[str] = None
user_type: Optional[str] = None
company_name: Optional[str] = None
email_verified: bool = False
roles: List[str] = Field(default_factory=list)
class UserInDB(IDModelMixin, DateTimeModelMixin, User):
"""
数据库存储模型(私有字段)
"""
salt: str = ""
hashed_password: str = ""
def check_password(self, password: str) -> bool:
return security.verify_password(self.salt + password, self.hashed_password)
def change_password(self, password: str) -> None:
self.salt = security.generate_salt()
self.hashed_password = security.get_password_hash(self.salt + password)