Registrace, kontrola prihlaseni uzivatele ve sprave letadel
This commit is contained in:
@@ -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,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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user