Skip to content

Commit

Permalink
improve layout templating
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 24, 2024
1 parent a4aab1b commit 6666f9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
31 changes: 14 additions & 17 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
get_user_assets,
is_within_timeframe,
login_required,
DEFAULT_SSO_PROVIDER,
)
from util.redis import REDIS
from util.sso import SSO_CONFIG
Expand Down Expand Up @@ -144,27 +145,23 @@ def before_request():


@app.context_processor
def login_providers():
result = {}

for provider, config in CONFIG["oauth2_providers"].items():
result[provider] = SSO_CONFIG[provider]["display_name"]

return {"login_providers": result}


@app.context_processor
def start_time_alert():
# if g.user is set, the user was successfully logged in (see above)
if g.userid:
return {"start_time": None}
def layout_context_variables():
result = {
"default_sso_provider": DEFAULT_SSO_PROVIDER,
"source_url": CONFIG["FAQ"]["SOURCE"],
"sso_providers": {},
"start_time": {},
}

start_time = datetime.fromtimestamp(CONFIG["TIME_MIN"], timezone.utc)

if start_time < datetime.now(timezone.utc):
return {"start_time": None}
for provider, config in CONFIG["oauth2_providers"].items():
result["sso_providers"][provider] = SSO_CONFIG[provider]["display_name"]

if not g.userid and start_time > datetime.now(timezone.utc):
result["start_time"] = start_time.strftime("%F %T")

return {"start_time": start_time.strftime("%F %T")}
return result


@app.route("/login/<provider>")
Expand Down
12 changes: 5 additions & 7 deletions templates/layout.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
</a></li>
<li><a href="{{ url_for("logout") }}">Logout</a></li>
{% else %}
{% for slug, name in login_providers.items() %}
<li><a href="{{ url_for("login", provider=slug) }}">Login / Sign up using {{ name }}</a></li>
{% for slug, name in sso_providers.items() %}
<li><a href="{{ url_for("login", provider=slug) }}"{% if slug==default_sso_provider %} style="font-weight: bolder;"{% endif %}>Login / Sign up using {{ name }}</a></li>
{% endfor %}
{% endif %}
</ul>
Expand All @@ -61,11 +61,9 @@
<hr/>
<div class='text-centered'>
<p>
Share your projects via info-beamer.
<a href="{{ url_for("faq") }}">FAQ / Contact</a>.
</p>
<p>
Screens run <a href='https://info-beamer.com'><img src="{{ url_for("static", filename="logo.png") }}">info-beamer</a> on Raspberry Pis.
<a href="{{ url_for("faq") }}">FAQ / Contact</a> |
<a href="{{ source_url }}">This project is open source</a> |
Screens run <a href="https://info-beamer.com"><img src="{{ url_for("static", filename="logo.png") }}">info-beamer</a> on Raspberry Pis.
<br/><br/>
</div>
</div>
Expand Down

0 comments on commit 6666f9e

Please sign in to comment.