mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 03:04:27 +08:00
Use built-in OAuth2PasswordRequestForm for login
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from starlette import status
|
||||
|
||||
from fastapi_users.db import UserDBInterface
|
||||
from fastapi_users.models import UserCreate, UserDB, UserLogin
|
||||
from fastapi_users.models import UserCreate, UserDB
|
||||
from fastapi_users.password import get_password_hash
|
||||
|
||||
|
||||
@ -19,8 +20,8 @@ class UserRouter:
|
||||
return created_user
|
||||
|
||||
@router.post('/login')
|
||||
async def login(user_login: UserLogin):
|
||||
user = await userDB.authenticate(user_login)
|
||||
async def login(credentials: OAuth2PasswordRequestForm = Depends()):
|
||||
user = await userDB.authenticate(credentials)
|
||||
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
Reference in New Issue
Block a user