Registrace, kontrola prihlaseni uzivatele ve sprave letadel

This commit is contained in:
Michal Kváček
2023-08-15 10:31:06 +02:00
parent 97295c17c0
commit 33e0a35f4b
5 changed files with 24 additions and 16 deletions
+6 -6
View File
@@ -1,13 +1,13 @@
from fastapi_jwt.jwt import JwtAccess, JwtRefresh
class BaseEndpoint:
def __init__(self, *args, **kwargs):
self.db = kwargs.get("db")
super().__init__(*args, **kwargs)
def __init__(self, db):
self.db = db
class AuthEndpoint:
def __init__(self, *args, **kwargs):
self.access_security: JwtAccess = kwargs.get("access_token")
self.refresh_security: JwtRefresh = kwargs.get("refresh_token")
super().__init__()
self.access_security: JwtAccess = kwargs.pop("access_token")
self.refresh_security: JwtRefresh = kwargs.pop("refresh_token")
super().__init__(*args, **kwargs)
+1 -2
View File
@@ -1,6 +1,5 @@
from fastapi import HTTPException
from fastapi_jwt import JwtAuthorizationCredentials
from passlib.hash import bcrypt
from sqlalchemy import select
from starlette.responses import Response
@@ -14,7 +13,7 @@ class LoginInput(BaseModel):
password: str
class LoginEndpoint(BaseEndpoint, AuthEndpoint):
class LoginEndpoint(AuthEndpoint, BaseEndpoint):
async def on_post(self, user_data: LoginInput, resp: Response) -> dict:
query = select(User).filter_by(email=user_data.email)
logged_user = (await self.db.scalars(query)).first()
+6 -6
View File
@@ -32,13 +32,13 @@ class RegistrationEndpoint(BaseEndpoint):
if existing_user:
raise HTTPException(status_code=422, detail="User already exists")
model = User(
name=user_data.name,
email=user_data.email,
password_hashed=bcrypt.hash(user_data.password)
)
model = await User.create(self.db, {
"name": user_data.name,
"email": user_data.email,
"password_hashed": bcrypt.hash(user_data.password),
"description": ""
})
self.db.add(model)
await self.db.commit()
return model.as_dict()