添加登录功能:JWT认证、注册、登录、前端登录页面
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Text, func
|
||||
from database import Base
|
||||
import hashlib
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""用户表"""
|
||||
__tablename__ = "user"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||
username = Column(String(50), unique=True, nullable=False, index=True, comment="用户名")
|
||||
password_hash = Column(String(128), nullable=False, comment="密码哈希")
|
||||
nickname = Column(String(50), nullable=True, comment="昵称")
|
||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||||
|
||||
def set_password(self, password):
|
||||
self.password_hash = hashlib.sha256(password.encode()).hexdigest()
|
||||
|
||||
def check_password(self, password):
|
||||
return self.password_hash == hashlib.sha256(password.encode()).hexdigest()
|
||||
|
||||
|
||||
class Inventory(Base):
|
||||
|
||||
Reference in New Issue
Block a user