File size: 862 Bytes
0632cd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import uuid

from fastapi import Request
from sqladmin.authentication import AuthenticationBackend as AuthBackendAdmin


class AdminAuth(AuthBackendAdmin):
    async def login(self, request: Request) -> bool:
        form = await request.form()
        username, password = form["username"], form["password"]
        if username == 'hectool24' and password == 'hectoolshopify2024@':
            request.session.update({"session": str(uuid.uuid4())})
            return True
        return False

    async def logout(self, request: Request) -> bool:
        request.session.clear()
        return True

    async def authenticate(self, request: Request) -> bool:
        token = request.session.get("session")
        if not token:
            return False
        return True


authentication_backend_admin = AdminAuth(secret_key=os.getenv('SECRET'))