Skip to content

Commit 2002b38

Browse files
Reset email, password, fix tokens (fix #21, #4) (#22)
1 parent 41d0acf commit 2002b38

27 files changed

Lines changed: 735 additions & 326 deletions

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine
2020
- uses: actions/setup-python@v4
2121
with:
22-
python-version: '3.10'
22+
python-version: '3.11'
2323
- name: Install dependencies
2424
run: |
2525
python -m ensurepip

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM python:3.10
2-
WORKDIR /app
1+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
2+
ENV APP_NAME=auth_backend
3+
ENV APP_MODULE=${APP_NAME}.routes.base:app
34

45
COPY ./requirements.txt /app/
5-
RUN pip install --no-cache-dir -r /app/requirements.txt
6+
RUN pip install -U -r /app/requirements.txt
67

7-
ADD gunicorn_conf.py alembic.ini /app/
8-
ADD migrations /app/migrations
9-
ADD auth_backend /app/auth_backend
8+
COPY ./alembic.ini /alembic.ini
9+
COPY ./migrations /migrations/
1010

11-
CMD [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-c", "/app/gunicorn_conf.py", "auth_backend.routes.base:app" ]
11+
COPY ./${APP_NAME} /app/${APP_NAME}

auth_backend/__main__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import logging
2+
13
import uvicorn
24

35
from auth_backend.routes import app
46

57
if __name__ == '__main__':
8+
9+
logging.basicConfig(
10+
filename=f'logger_{__name__}.log',
11+
level=logging.INFO,
12+
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
13+
datefmt='%Y-%m-%d %H:%M:%S',
14+
)
15+
616
uvicorn.run(app)

auth_backend/auth_plugins/auth_method.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
import re
44
from abc import abstractmethod, ABCMeta
5+
from datetime import datetime
56

67
from fastapi import APIRouter
8+
from pydantic import constr
79

8-
from datetime import datetime
9-
from auth_backend.base import Base, Token
10+
from auth_backend.base import Base
1011

1112

12-
class Session(Token):
13+
class Session(Base):
14+
token: constr(min_length=1)
1315
expires: datetime
1416
id: int
1517
user_id: int
@@ -22,25 +24,26 @@ class AuthMethodMeta(metaclass=ABCMeta):
2224
router: APIRouter
2325
prefix: str
2426
tags: list[str] = []
27+
fields: list[str] = []
2528

2629
@classmethod
2730
def get_name(cls) -> str:
2831
return re.sub(r"(?<!^)(?=[A-Z])", "_", cls.__name__).lower()
2932

3033
def __init__(self):
3134
self.router = APIRouter()
32-
self.router.add_api_route("/registration", self.register, methods=["POST"])
33-
self.router.add_api_route("/login", self.login, methods=["POST"], response_model=Session)
35+
self.router.add_api_route("/registration", self._register, methods=["POST"])
36+
self.router.add_api_route("/login", self._login, methods=["POST"], response_model=Session)
3437

3538
def __init_subclass__(cls, **kwargs):
3639
AUTH_METHODS[cls.__name__] = cls
3740

3841
@staticmethod
3942
@abstractmethod
40-
async def register(**kwargs) -> object:
43+
async def _register(**kwargs) -> object:
4144
raise NotImplementedError()
4245

4346
@staticmethod
4447
@abstractmethod
45-
async def login(**kwargs) -> Session:
48+
async def _login(**kwargs) -> Session:
4649
raise NotImplementedError()

0 commit comments

Comments
 (0)