🐛 fix(login.py): change argument type of create_user_token function from str to User to improve type safety and clarity
🐛 fix(login.py): remove unnecessary type ignore comment in create_user_token function 🐛 fix(login.py): remove unnecessary type ignore comment in return statement of login_to_get_access_token function 🐛 fix(users.py): remove unnecessary async keyword from read_current_user function 🐛 fix(users.py): remove unnecessary async keyword from read_all_users function 🐛 fix(users.py): remove unnecessary async keyword from add_user function 🐛 fix(users.py): remove unnecessary async keyword from add_super_user_to_testing_purposes function
This commit is contained in:
parent
3c6d46021d
commit
056ce51ad0
2 changed files with 7 additions and 7 deletions
|
|
@ -11,15 +11,15 @@ from langflow.auth.auth import (
|
|||
|
||||
from sqlalchemy.orm import Session
|
||||
from langflow.services.utils import get_session
|
||||
from langflow.database.models.user import User
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def create_user_token(user: str) -> dict:
|
||||
def create_user_token(user: User) -> dict:
|
||||
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
access_token = create_access_token(
|
||||
# type: ignore
|
||||
data={"sub": user.username},
|
||||
expires_delta=access_token_expires,
|
||||
)
|
||||
|
|
@ -32,7 +32,7 @@ async def login_to_get_access_token(
|
|||
form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_session)
|
||||
):
|
||||
if user := authenticate_user(db, form_data.username, form_data.password):
|
||||
return create_user_token(user) # type: ignore
|
||||
return create_user_token(user)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ def get_password_hash(password):
|
|||
|
||||
|
||||
@router.get("/user", response_model=UserListModel)
|
||||
async def read_current_user(current_user: User = Depends(get_current_active_user)):
|
||||
def read_current_user(current_user: User = Depends(get_current_active_user)):
|
||||
return current_user
|
||||
|
||||
|
||||
@router.get("/users", response_model=List[UserListModel])
|
||||
async def read_all_users(
|
||||
def read_all_users(
|
||||
skip: int = 0,
|
||||
limit: int = 10,
|
||||
_: Session = Depends(get_current_active_user),
|
||||
|
|
@ -36,7 +36,7 @@ async def read_all_users(
|
|||
|
||||
|
||||
@router.post("/user", response_model=User)
|
||||
async def add_user(
|
||||
def add_user(
|
||||
user: UserAddModel,
|
||||
_: Session = Depends(get_current_active_user),
|
||||
db: Session = Depends(get_session),
|
||||
|
|
@ -60,7 +60,7 @@ async def add_user(
|
|||
|
||||
# TODO: Remove - Just for testing purposes
|
||||
@router.post("/super_user", response_model=User)
|
||||
async def add_super_user_to_testing_purposes(db: Session = Depends(get_session)):
|
||||
def add_super_user_to_testing_purposes(db: Session = Depends(get_session)):
|
||||
new_user = User(username="superuser", password="12345", is_superuser=True)
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue