feat(auth): enhance auxiliary authentication

This commit is contained in:
InfinityPacer
2024-10-19 03:16:04 +08:00
parent 386ff672a7
commit d8e7c7e6d7
9 changed files with 294 additions and 167 deletions
+2 -20
View File
@@ -1,11 +1,7 @@
from typing import Tuple, Any
from sqlalchemy import Boolean, Column, Integer, String, Sequence, JSON
from sqlalchemy import Boolean, Column, Integer, JSON, Sequence, String
from sqlalchemy.orm import Session
from app.core.security import verify_password
from app.db import db_query, db_update, Base
from app.utils.otp import OtpUtils
from app.db import Base, db_query, db_update
class User(Base):
@@ -35,20 +31,6 @@ class User(Base):
# 用户个性化设置 json
settings = Column(JSON, default=dict)
@staticmethod
@db_query
def authenticate(db: Session, name: str, password: str,
otp_password: str) -> Tuple[bool, Any]:
user = db.query(User).filter(User.name == name).first()
if not user:
return False, None
if not verify_password(password, str(user.hashed_password)):
return False, user
if user.is_otp:
if not otp_password or not OtpUtils.check(str(user.otp_secret), otp_password):
return False, user
return True, user
@staticmethod
@db_query
def get_by_name(db: Session, name: str):