Added authentication forms and routes
This commit is contained in:
88
src/myfasthtml/auth/pages/LoginPage.py
Normal file
88
src/myfasthtml/auth/pages/LoginPage.py
Normal file
@@ -0,0 +1,88 @@
|
||||
from fasthtml.components import *
|
||||
|
||||
|
||||
class LoginPage:
|
||||
def __init__(self, error_message=None, success_message=None):
|
||||
self.error_message = error_message
|
||||
self.success_message = success_message
|
||||
|
||||
def render(self):
|
||||
message_alert = None
|
||||
if self.error_message:
|
||||
message_alert = Div(
|
||||
P(self.error_message, cls="text-sm"),
|
||||
cls="bg-error border border-red-400 text-red-700 px-4 py-3 rounded mb-4"
|
||||
)
|
||||
elif self.success_message:
|
||||
message_alert = Div(
|
||||
P(self.success_message, cls="text-sm"),
|
||||
cls="bg-success border border-green-400 text-green-700 px-4 py-3 rounded mb-4"
|
||||
)
|
||||
|
||||
return Div(
|
||||
# Page title
|
||||
H1("Sign In", cls="text-3xl font-bold text-center mb-6"),
|
||||
|
||||
# Login Form
|
||||
Div(
|
||||
# Message alert
|
||||
message_alert if message_alert else "",
|
||||
|
||||
# Email login form
|
||||
Form(
|
||||
# Email field
|
||||
Div(
|
||||
Label("Email", For="email", cls="block text-sm font-medium text-gray-700 mb-1"),
|
||||
Input(
|
||||
type="email",
|
||||
id="email",
|
||||
name="email",
|
||||
placeholder="you@example.com",
|
||||
required=True,
|
||||
cls="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2"
|
||||
),
|
||||
cls="mb-4"
|
||||
),
|
||||
|
||||
# Password field
|
||||
Div(
|
||||
Label("Password", For="password", cls="block text-sm font-medium text-gray-700 mb-1"),
|
||||
Input(
|
||||
type="password",
|
||||
id="password",
|
||||
name="password",
|
||||
placeholder="Your password",
|
||||
required=True,
|
||||
cls="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2"
|
||||
),
|
||||
cls="mb-6"
|
||||
),
|
||||
|
||||
# Submit button
|
||||
Button(
|
||||
"Sign In",
|
||||
type="submit",
|
||||
cls="btn w-full font-bold py-2 px-4 rounded"
|
||||
),
|
||||
|
||||
action="/login-p",
|
||||
method="post",
|
||||
cls="mb-6"
|
||||
),
|
||||
|
||||
# Registration link
|
||||
Div(
|
||||
P(
|
||||
"Don't have an account? ",
|
||||
A("Register here", href="/register", cls="text-blue-600 hover:underline"),
|
||||
cls="text-sm text-gray-600 text-center"
|
||||
)
|
||||
),
|
||||
|
||||
cls="p-8 rounded-lg shadow-2xl max-w-md mx-auto"
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
def __ft__(self):
|
||||
return self.render()
|
||||
Reference in New Issue
Block a user