First Working version. I can add table
This commit is contained in:
63
src/components/login/LoginApp.py
Normal file
63
src/components/login/LoginApp.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import logging
|
||||
|
||||
from fasthtml.fastapp import fast_app
|
||||
from starlette.responses import RedirectResponse
|
||||
|
||||
from auth.auth_manager import AuthManager
|
||||
from auth.email_auth import EmailAuth
|
||||
from components.login.constants import Routes, LOGIN_INSTANCE_ID
|
||||
from components.page_layout_new import page_layout_new
|
||||
from core.instance_manager import InstanceManager
|
||||
|
||||
logger = logging.getLogger("LoggingApp")
|
||||
|
||||
login_app, rt = fast_app()
|
||||
|
||||
|
||||
@rt(Routes.Login)
|
||||
def get(error_message: str = None, success_message: str = None):
|
||||
"""Handler for the login page route."""
|
||||
instance = InstanceManager.get(None, LOGIN_INSTANCE_ID)
|
||||
return page_layout_new(None,
|
||||
instance.settings_manager,
|
||||
instance.login_page(error_message, success_message))
|
||||
|
||||
|
||||
@rt(Routes.Logout)
|
||||
def get(session):
|
||||
"""Handler for logout."""
|
||||
# Clear session data
|
||||
AuthManager.logout_user(session)
|
||||
|
||||
# Redirect to login page
|
||||
return RedirectResponse('/login', status_code=303)
|
||||
|
||||
|
||||
@rt(Routes.LoginByEmail)
|
||||
def post(session, email: str, password: str):
|
||||
"""Handler for email login."""
|
||||
# Authenticate user
|
||||
success, message, user_data = EmailAuth.authenticate(
|
||||
email=email,
|
||||
password=password
|
||||
)
|
||||
|
||||
instance = InstanceManager.get(None, LOGIN_INSTANCE_ID)
|
||||
|
||||
if not success:
|
||||
return page_layout_new(
|
||||
session,
|
||||
instance.settings_manager,
|
||||
instance.login_page(error_message=message),
|
||||
)
|
||||
|
||||
# Log in user by setting session data
|
||||
AuthManager.login_user(session, user_data)
|
||||
|
||||
# Make sure that the settings are created for this user
|
||||
user_id = user_data["id"]
|
||||
user_email = user_data["email"]
|
||||
instance.init_user(user_id, user_email)
|
||||
|
||||
# Redirect to home page
|
||||
return RedirectResponse('/', status_code=303)
|
||||
Reference in New Issue
Block a user