feat 支持Emby/Jellyfin登录认证

This commit is contained in:
jxxghp
2023-06-20 13:09:11 +08:00
parent 47f5942e22
commit 0776a0b235
17 changed files with 117 additions and 87 deletions
+11 -1
View File
@@ -6,10 +6,12 @@ from fastapi.security import OAuth2PasswordRequestForm
from sqlalchemy.orm import Session
from app import schemas
from app.chain.user import UserChain
from app.core import security
from app.core.config import settings
from app.db import get_db
from app.db.models.user import User
from app.log import logger
router = APIRouter()
@@ -21,13 +23,21 @@ async def login_access_token(
"""
获取认证Token
"""
# 检查数据库
user = User.authenticate(
db=db,
name=form_data.username,
password=form_data.password
)
if not user:
raise HTTPException(status_code=400, detail="用户名或密码不正确")
# 请求协助认证
logger.warn("登录用户本地不匹配,尝试辅助认证 ...")
token = UserChain().user_authenticate(form_data.username, form_data.password)
if not token:
raise HTTPException(status_code=400, detail="用户名或密码不正确")
else:
logger.info(f"辅助认证成功,用户信息: {token}")
user = schemas.User(id=-1, name=form_data.username, is_active=True, is_superuser=False)
elif not user.is_active:
raise HTTPException(status_code=400, detail="用户未启用")
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)