Merge branch 'authentication' into login-auth
This commit is contained in:
commit
dd80f857a9
2 changed files with 11 additions and 4 deletions
|
|
@ -34,6 +34,7 @@ async def get_current_user(
|
||||||
detail="Could not validate credentials",
|
detail="Could not validate credentials",
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||||
user_id: UUID = payload.get("sub") # type: ignore
|
user_id: UUID = payload.get("sub") # type: ignore
|
||||||
|
|
@ -121,7 +122,14 @@ def create_refresh_token(refresh_token: str):
|
||||||
def authenticate_user(
|
def authenticate_user(
|
||||||
username: str, password: str, db: Session = Depends(get_session)
|
username: str, password: str, db: Session = Depends(get_session)
|
||||||
) -> User | None:
|
) -> User | None:
|
||||||
if user := get_user_by_username(db, username):
|
user = get_user_by_username(db, username)
|
||||||
return user if verify_password(password, user.password) else None
|
|
||||||
else:
|
if not user:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not user.is_active:
|
||||||
|
if not user.last_login_at:
|
||||||
|
raise HTTPException(status_code=400, detail="Waiting for approval")
|
||||||
|
raise HTTPException(status_code=400, detail="Inactive user")
|
||||||
|
|
||||||
|
return user if verify_password(password, user.password) else None
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from sqlalchemy.orm import Session
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
from fastapi.security import OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordRequestForm
|
||||||
|
|
||||||
|
|
||||||
from langflow.services.utils import get_session
|
from langflow.services.utils import get_session
|
||||||
from langflow.database.models.token import Token
|
from langflow.database.models.token import Token
|
||||||
from langflow.auth.auth import (
|
from langflow.auth.auth import (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue