fix: Flask url_for compatibility shim + login template routes
This commit is contained in:
parent
ad73af47b7
commit
d49844c1fe
2 changed files with 32 additions and 5 deletions
|
|
@ -104,6 +104,33 @@ def _flex(d):
|
|||
return d
|
||||
|
||||
|
||||
_URL_MAP = {
|
||||
# Flask-style endpoint names → FastAPI URL paths
|
||||
"dashboard": "/dashboard",
|
||||
"catalog": "/catalog",
|
||||
"corporate_memory": "/corporate-memory",
|
||||
"corporate_memory_admin": "/corporate-memory/admin",
|
||||
"activity_center": "/activity-center",
|
||||
"index": "/",
|
||||
"auth.login": "/login",
|
||||
"auth.logout": "/login", # No logout route — redirect to login
|
||||
"password_auth.login_email": "/auth/password/login",
|
||||
"password_auth.reset_request": "/auth/password/reset",
|
||||
"password_auth.request_access": "/auth/password/setup",
|
||||
"email_auth.login_email_form": "/login/email",
|
||||
"email_auth.send_magic_link": "/auth/email/send-link",
|
||||
"register": "/auth/password/setup",
|
||||
}
|
||||
|
||||
|
||||
def _url_for_shim(endpoint: str, **kw) -> str:
|
||||
"""Flask url_for compatibility — maps endpoint names to FastAPI paths."""
|
||||
if endpoint == "static":
|
||||
filename = kw.get("filename", "")
|
||||
return f"/static/{filename}"
|
||||
return _URL_MAP.get(endpoint, f"/{endpoint}")
|
||||
|
||||
|
||||
def _build_context(request: Request, user: Optional[dict] = None, **extra) -> dict:
|
||||
"""Build template context with config, user, and theme."""
|
||||
class ConfigProxy:
|
||||
|
|
@ -132,7 +159,7 @@ def _build_context(request: Request, user: Optional[dict] = None, **extra) -> di
|
|||
"static_url": lambda path: f"/static/{path}",
|
||||
# Flask compatibility shims for templates
|
||||
"get_flashed_messages": lambda **kwargs: [],
|
||||
"url_for": lambda endpoint, **kw: f"/{endpoint}",
|
||||
"url_for": lambda endpoint, **kw: _url_for_shim(endpoint, **kw),
|
||||
"session": _FlexDict({"user": user}) if user else _FlexDict(),
|
||||
}
|
||||
# Flex all extra context values for template compatibility
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<!-- Sign In Tab -->
|
||||
<div id="signin-tab" class="auth-tab-content active">
|
||||
<form method="POST" action="{{ url_for('password_auth.login_email') }}" class="login-form">
|
||||
<form method="POST" action="/auth/password/login" class="login-form">
|
||||
<div class="form-group">
|
||||
<label for="email-signin">Email Address</label>
|
||||
<input type="email"
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
</form>
|
||||
|
||||
<div class="login-links">
|
||||
<form method="POST" action="{{ url_for('password_auth.reset_request') }}" class="reset-form">
|
||||
<form method="POST" action="/auth/password/reset" class="reset-form">
|
||||
<input type="hidden" name="email" value="{{ email|default('', true) }}" id="reset-email">
|
||||
<button type="submit" class="btn btn-link">Forgot Password?</button>
|
||||
</form>
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
Enter your email to receive a setup link. You must be pre-approved by an administrator.
|
||||
</p>
|
||||
|
||||
<form method="POST" action="{{ url_for('password_auth.request_access') }}" class="login-form">
|
||||
<form method="POST" action="/auth/password/setup" class="login-form">
|
||||
<div class="form-group">
|
||||
<label for="email-signup">Email Address</label>
|
||||
<input type="email"
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
<span>or</span>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('auth.login') }}" class="btn btn-secondary btn-block">
|
||||
<a href="/auth/google/login" class="btn btn-secondary btn-block">
|
||||
<svg class="google-icon" viewBox="0 0 24 24" width="20" height="20">
|
||||
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
|
||||
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue