30 lines
920 B
Python
30 lines
920 B
Python
from sqlalchemy import Column, String, DateTime,Integer
|
|
from sqlalchemy.sql import func
|
|
from pydantic import BaseModel, Field
|
|
from .database import Base
|
|
|
|
# 数据库模型
|
|
class UserDB(Base):
|
|
__tablename__ = "users"
|
|
|
|
userid = Column(Integer, primary_key=True,autoincrement=True, index=True)
|
|
username = Column(String(50))
|
|
phone = Column(String(11), unique=True, index=True)
|
|
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
|
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Pydantic 模型
|
|
class UserLogin(BaseModel):
|
|
phone: str = Field(..., pattern="^1[3-9]\d{9}$")
|
|
verify_code: str = Field(..., min_length=6, max_length=6)
|
|
|
|
class UserInfo(BaseModel):
|
|
userid: int
|
|
username: str
|
|
phone: str
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class VerifyCodeRequest(BaseModel):
|
|
phone: str = Field(..., pattern="^1[3-9]\d{9}$") |