removed obsolete endpoints and added missing endpoints
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import logging
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Annotated, Dict, List, Optional
|
||||
from typing import Annotated, List, Optional
|
||||
|
||||
import bcrypt
|
||||
from fastapi import Depends, HTTPException, Request, Security, status
|
||||
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
|
||||
from fastapi.security import OAuth2, OAuth2PasswordBearer, SecurityScopes
|
||||
from fastapi.security.utils import get_authorization_scheme_param
|
||||
from fastapi import Depends, HTTPException, Security, status
|
||||
#from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
|
||||
from fastapi.security import (
|
||||
#OAuth2,
|
||||
OAuth2PasswordBearer,
|
||||
SecurityScopes
|
||||
)
|
||||
#from fastapi.security.utils import get_authorization_scheme_param
|
||||
from jose import JWTError, jwt
|
||||
from pydantic import ValidationError
|
||||
|
||||
@@ -19,7 +22,8 @@ from src.db.repository.admin import (
|
||||
is_database_empty,
|
||||
)
|
||||
from src.db.session import SessionLocal
|
||||
from src.schema.admin import ProfileModel, TokenData
|
||||
from src.schema.admin.token import TokenData
|
||||
from src.schema.user.profile import ProfileModel, to_model
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(
|
||||
tokenUrl="/token",
|
||||
@@ -161,13 +165,7 @@ async def get_current_active_user(
|
||||
) -> ProfileModel:
|
||||
if not current_user.enabled:
|
||||
raise HTTPException(status_code=400, detail="Inactive user")
|
||||
user_model = ProfileModel(
|
||||
username=current_user.user_name,
|
||||
email=current_user.email, # type: ignore
|
||||
first_name=current_user.first_name,
|
||||
last_name=current_user.last_name, # type: ignore
|
||||
active=current_user.enabled,
|
||||
) # type: ignore
|
||||
user_model = to_model(current_user)
|
||||
return user_model
|
||||
|
||||
|
||||
@@ -181,7 +179,7 @@ def get_current_user_from_token(token: str = Depends(oauth2_scheme)):
|
||||
payload = jwt.decode(
|
||||
token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]
|
||||
)
|
||||
username: str = payload.get("sub") # type: ignore
|
||||
username: Optional[str] = payload.get("sub")
|
||||
logger.info("username/email extracted is %s", username)
|
||||
if username is None:
|
||||
raise credentials_exception
|
||||
@@ -190,8 +188,12 @@ def get_current_user_from_token(token: str = Depends(oauth2_scheme)):
|
||||
with SessionLocal() as db:
|
||||
user = get_profile_by_email(email=username, db=db)
|
||||
if user is None:
|
||||
raise credentials_exception
|
||||
user = get_profile_by_username(username=username, db=db)
|
||||
if user is None:
|
||||
raise credentials_exception
|
||||
return user
|
||||
|
||||
|
||||
UserDep = Annotated[Profile, Depends(get_current_user_from_token)]
|
||||
|
||||
CurrentUser = Annotated[Profile, Depends(get_current_active_user)]
|
||||
|
||||
Reference in New Issue
Block a user