-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aSel1x/main
- Loading branch information
Showing
31 changed files
with
202 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
from typing import Self | ||
|
||
from app.core.db import Database | ||
|
||
from .security import Security | ||
from .users import Users | ||
|
||
|
||
class Logic: | ||
def __init__(self, db: Database): | ||
self.db = db | ||
self.security = Security() | ||
self.users = Users(self) | ||
|
||
@classmethod | ||
async def create(cls) -> Self: | ||
async with Database() as db: | ||
return cls(db) | ||
|
||
from .logic import Logic | ||
|
||
__all__ = ['Logic'] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from app.core import exps | ||
from app.models.auth import AccessToken | ||
|
||
if TYPE_CHECKING: | ||
from app.logic import Logic | ||
|
||
|
||
class Auth: | ||
def __init__(self, logic: 'Logic'): | ||
self.logic = logic | ||
|
||
async def generate_token( | ||
self, email: str, password: str | ||
) -> AccessToken | None: | ||
if (user := await self.logic.db.user.retrieve_by_email(email)) is None: | ||
raise exps.UserNotFoundException() | ||
if not self.logic.security.pwd.checkpwd(password, user.password): | ||
raise exps.UserIsCorrectException() | ||
access_token = self.logic.security.jwt.encode_token( | ||
{'id': user.id}, 1440 | ||
) | ||
return AccessToken(token=access_token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Self, AsyncGenerator | ||
from contextlib import asynccontextmanager | ||
|
||
from app.core.db import Database | ||
|
||
from .security import Security | ||
from .users import Users | ||
from .auth import Auth | ||
|
||
|
||
class Logic: | ||
def __init__(self, db: Database): | ||
self.db = db | ||
self.security = Security() | ||
self.users = Users(self) | ||
self.auth = Auth(self) | ||
|
||
@classmethod | ||
@asynccontextmanager | ||
async def create(cls) -> AsyncGenerator[Self, None]: | ||
async with Database() as db: | ||
yield cls(db) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
from app.core.settings import settings | ||
|
||
from .jwt import JWT | ||
from .pwd import PWD | ||
|
||
|
||
class Security: | ||
def __init__(self): | ||
self.jwt = JWT(settings.APP_SECRET_KEY) | ||
self.pwd = PWD() | ||
|
||
from .security import Security | ||
|
||
__all__ = ['Security'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from app.core.settings import settings | ||
|
||
from .jwt import JWT | ||
from .pwd import PWD | ||
|
||
|
||
class Security: | ||
def __init__(self): | ||
self.jwt = JWT(settings.APP_SECRET_KEY) | ||
self.pwd = PWD() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.