Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
86a3d05f7e | |||
9fac430654 | |||
f56eb9db92 | |||
15062c029f | |||
6c51c7469b | |||
952b0211ba |
@@ -13,15 +13,19 @@ ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
|||||||
|
|
||||||
@router.post("/token", tags=["token"])
|
@router.post("/token", tags=["token"])
|
||||||
async def login_for_access_token(
|
async def login_for_access_token(
|
||||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
|
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||||
|
remember_me: bool = Form(False)):
|
||||||
user = users_token.authenticate_user(form_data.username, form_data.password)
|
user = users_token.authenticate_user(form_data.username, form_data.password)
|
||||||
|
expires_access_token_time = ACCESS_TOKEN_EXPIRE_MINUTES
|
||||||
|
if remember_me:
|
||||||
|
expires_access_token_time=120
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Incorrect username or password",
|
detail="Incorrect username or password",
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
access_token_expires = timedelta(minutes=expires_access_token_time)
|
||||||
access_token = users_token.create_access_token(
|
access_token = users_token.create_access_token(
|
||||||
data={"sub": user.username}, expires_delta=access_token_expires
|
data={"sub": user.username}, expires_delta=access_token_expires
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user