mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix message
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
from typing import Tuple, Optional
|
||||
from typing import Tuple, Any
|
||||
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import schemas
|
||||
from app.core.security import verify_password
|
||||
from app.db import db_query, db_update, Base
|
||||
from app.utils.otp import OtpUtils
|
||||
@@ -39,14 +38,14 @@ class User(Base):
|
||||
@staticmethod
|
||||
@db_query
|
||||
def authenticate(db: Session, name: str, password: str,
|
||||
otp_password: str) -> Tuple[bool, Optional[schemas.User]]:
|
||||
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(user.otp_secret, otp_password):
|
||||
if not otp_password or not OtpUtils.check(str(user.otp_secret), otp_password):
|
||||
return False, user
|
||||
return True, user
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
from app.db import DbOper
|
||||
from app.db.models.user import User
|
||||
|
||||
|
||||
class UserOper(DbOper):
|
||||
"""
|
||||
用户管理
|
||||
"""
|
||||
|
||||
def get_permissions(self, name: str) -> dict:
|
||||
"""
|
||||
获取用户权限
|
||||
"""
|
||||
user = User.get_by_name(self._db, name)
|
||||
if user:
|
||||
try:
|
||||
return json.loads(user.permissions)
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
def get_settings(self, name: str) -> Optional[dict]:
|
||||
"""
|
||||
获取用户个性化设置,返回None表示用户不存在
|
||||
"""
|
||||
user = User.get_by_name(self._db, name)
|
||||
if user:
|
||||
try:
|
||||
if user.settings:
|
||||
return json.loads(user.settings)
|
||||
return {}
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return None
|
||||
|
||||
def get_setting(self, name: str, key: str) -> Optional[str]:
|
||||
"""
|
||||
获取用户个性化设置
|
||||
"""
|
||||
settings = self.get_settings(name)
|
||||
if settings:
|
||||
return settings.get(key)
|
||||
return None
|
||||
Reference in New Issue
Block a user