77from app .services import auth
88from app .schemas import Token , TokenPayload , Community
99from app .services .database .models import Community as DBCommunity
10- from services .database .orm .community import get_community_by_username
10+ from app . services .database .orm .community import get_community_by_username
1111
1212oauth2_scheme = OAuth2PasswordBearer (tokenUrl = "/authentication/token" )
1313
1414def setup ():
1515 router = APIRouter (prefix = '/authentication' , tags = ['authentication' ])
16- async def authenticate_community (request : Request , username : str , password : str ):
17- # Valida se o usuário existe e se a senha está correta
18- found_community = await get_community_by_username (
19- username = username ,
20- session = request .app .db_session_factory
21- )
22- if not found_community or not auth .verify_password (password , found_community .password ):
16+ async def authenticate_community ( request : Request , username : str , password : str ):
17+ # Valida se o usuário existe e se a senha está correta
18+ session : AsyncSession = request .app .db_session_factory
19+ found_community = await get_community_by_username (
20+ username = username ,
21+ session = session
22+ )
23+ if not found_community or not auth .verify_password (password , found_community .password ):
2324 return None
24- return found_community
25+ return found_community
2526
2627
2728 #### Teste
@@ -41,7 +42,7 @@ async def create_community(request: Request ):
4142 @router .post ("/token" , response_model = Token )
4243 async def login_for_access_token (request : Request , form_data : OAuth2PasswordRequestForm = Depends () ) :
4344 # Rota de login: valida credenciais e retorna token JWT
44- community = await authenticate_community (form_data .username , form_data .password , request . app . db_session_factory )
45+ community = await authenticate_community ( request , form_data .username , form_data .password )
4546 if not community :
4647 raise HTTPException (
4748 status_code = status .HTTP_401_UNAUTHORIZED ,
0 commit comments