1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

appstore: add usermenu with logout option

This commit is contained in:
Alexandre Aubin 2023-09-18 16:42:28 +02:00
parent 038af2cc42
commit abc1d038f1
2 changed files with 60 additions and 23 deletions

View file

@ -284,6 +284,22 @@ def sso_login_callback():
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
session.clear() session.clear()
# Only use the current referer URI if it's on the same domain as the current route
# to avoid XSS or whatever...
referer = request.environ.get("HTTP_REFERER")
if referer:
if referer.startswith("http://"):
referer = referer[len("http://"):]
if referer.startswith("https://"):
referer = referer[len("https://"):]
if "/" not in referer:
referer = referer + "/"
domain, uri = referer.split("/", 1)
if domain == request.environ.get("HTTP_HOST"):
return redirect("/" + uri)
return redirect("/") return redirect("/")

View file

@ -91,11 +91,12 @@
{{ _("Login using YunoHost's forum") }} {{ _("Login using YunoHost's forum") }}
</a> </a>
{% else %} {% else %}
<div class="relative">
<button <button
id="toggleUserMenu"
type="button" type="button"
class="group flex shrink-0 items-center rounded-lg transition" class="group flex shrink-0 items-center rounded-lg transition"
> >
<span class="sr-only">{{ _("Menu") }}</span>
<img <img
alt="Man" alt="Man"
src="{{ user['avatar_url'] }}" src="{{ user['avatar_url'] }}"
@ -106,15 +107,26 @@
</p> </p>
<i class="fa fa-caret-down fa-fw" aria-hidden="true"></i> <i class="fa fa-caret-down fa-fw" aria-hidden="true"></i>
</button> </button>
<!-- <div
id="userMenu"
class="hidden absolute end-0 z-10 mt-2 w-56 rounded-md border border-gray-100 bg-white shadow-lg"
role="menu"
>
<div class="p-2">
<a <a
class="block rounded-md bg-teal-600 px-5 py-2.5 text-sm font-medium text-white transition hover:bg-teal-700" href="/logout"
href="{{ url_for('logout') }}" class="block rounded-lg px-4 py-2 text-sm text-gray-500 hover:bg-gray-50 hover:text-gray-700"
role="menuitem"
> >
Logout Logout
</a> </a>
--> </div>
</div>
</div>
{% endif %} {% endif %}
</div> </div>
<button <button
@ -134,4 +146,13 @@
<footer class="h-5 mt-5"></footer> <footer class="h-5 mt-5"></footer>
</body> </body>
{% if user %}
<script>
let toggleUserMenu = document.getElementById('toggleUserMenu');
toggleUserMenu.addEventListener('click', () => {
document.getElementById('userMenu').classList.toggle("hidden");
});
</script>
{% endif %}
</html> </html>