添加登录功能:JWT认证、注册、登录、前端登录页面

This commit is contained in:
cnbugs
2026-06-01 15:54:29 +08:00
parent 188edfa287
commit 0d6c9d26c0
5 changed files with 289 additions and 23 deletions
+18
View File
@@ -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):