Skip to content

Commit

Permalink
Add profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Oct 14, 2024
1 parent b4c8b51 commit 46a9006
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 126 deletions.
2 changes: 0 additions & 2 deletions amt/api/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def get_display_text(self, translations: NullTranslations | None = None) -> str:


class Navigation:
HOMEPAGE = BaseNavigationItem(display_text=DisplayText.HOME, url="/", icon="rvo-icon-home")
PROJECTS_ROOT = BaseNavigationItem(
display_text=DisplayText.PROJECTS, url=["/projects/", "/project/"], icon="rvo-icon-publicatie"
)
Expand Down Expand Up @@ -236,7 +235,6 @@ def resolve_navigation_items(
def get_main_menu(request: Request, translations: NullTranslations) -> list[NavigationItem]:
# main menu items are the same for all pages
main_menu_items = [
NavigationItem(Navigation.HOMEPAGE, translations=translations),
NavigationItem(Navigation.PROJECTS_ROOT, translations=translations),
]

Expand Down
10 changes: 9 additions & 1 deletion amt/api/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse, RedirectResponse, Response

from amt.api.deps import templates
from amt.core.authorization import get_user
from amt.core.exceptions import AMTAuthorizationFlowError

Expand Down Expand Up @@ -60,4 +61,11 @@ async def auth_callback(request: Request) -> Response: # pragma: no cover
if user:
request.session["user"] = dict(user) # type: ignore
request.session["id_token"] = token["id_token"] # type: ignore
return RedirectResponse(url="/")
return RedirectResponse(url="/projects/")


@router.get("/profile", response_class=Response)
async def auth_profile(request: Request) -> HTMLResponse:
user = get_user(request)

return templates.TemplateResponse(request, "auth/profile.html.j2", {"user": user})
44 changes: 31 additions & 13 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ msgstr ""
msgid "Projects"
msgstr ""

#: amt/api/navigation.py:47
#: amt/api/navigation.py:47 amt/site/templates/auth/profile.html.j2:10
msgid "Overview"
msgstr ""

Expand Down Expand Up @@ -185,6 +185,32 @@ msgid ""
"later."
msgstr ""

#: amt/site/templates/auth/profile.html.j2:10
msgid "of"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:18
msgid "Logout"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:30
msgid "Edit image"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:34
msgid "Name"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:37
msgid "Email"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:40
#: amt/site/templates/parts/header.html.j2:92
#: amt/site/templates/parts/header.html.j2:151
msgid "Language"
msgstr ""

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:5
msgid "Not logged in"
msgstr ""
Expand All @@ -194,8 +220,9 @@ msgid "Please login to view this page"
msgstr ""

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:11
#: amt/site/templates/parts/header.html.j2:100
#: amt/site/templates/parts/header.html.j2:154
#: amt/site/templates/pages/landingpage.html.j2:16
#: amt/site/templates/parts/header.html.j2:103
#: amt/site/templates/parts/header.html.j2:161
msgid "Login"
msgstr ""

Expand Down Expand Up @@ -274,6 +301,7 @@ msgstr ""
msgid "AMT Placeholder informatie pagina's"
msgstr ""

#: amt/site/templates/pages/landingpage.html.j2:12
#: amt/site/templates/parts/footer.html.j2:4
#: amt/site/templates/parts/header.html.j2:8
msgid "Algorithm Management Toolkit"
Expand Down Expand Up @@ -305,16 +333,6 @@ msgstr ""
msgid "Everyone is welcome to make comments and suggestions."
msgstr ""

#: amt/site/templates/parts/header.html.j2:88
#: amt/site/templates/parts/header.html.j2:143
msgid "Language"
msgstr ""

#: amt/site/templates/parts/header.html.j2:109
#: amt/site/templates/parts/header.html.j2:162
msgid "Logout"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:3
#: amt/site/templates/projects/details_data.html.j2:3
#: amt/site/templates/projects/details_info.html.j2:3
Expand Down
47 changes: 34 additions & 13 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ msgstr ""
msgid "Projects"
msgstr ""

#: amt/api/navigation.py:47
#: amt/api/navigation.py:47 amt/site/templates/auth/profile.html.j2:10
msgid "Overview"
msgstr ""

Expand Down Expand Up @@ -186,6 +186,32 @@ msgid ""
"later."
msgstr ""

#: amt/site/templates/auth/profile.html.j2:10
msgid "of"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:18
msgid "Logout"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:30
msgid "Edit image"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:34
msgid "Name"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:37
msgid "Email"
msgstr ""

#: amt/site/templates/auth/profile.html.j2:40
#: amt/site/templates/parts/header.html.j2:92
#: amt/site/templates/parts/header.html.j2:151
msgid "Language"
msgstr ""

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:5
msgid "Not logged in"
msgstr ""
Expand All @@ -195,8 +221,9 @@ msgid "Please login to view this page"
msgstr ""

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:11
#: amt/site/templates/parts/header.html.j2:100
#: amt/site/templates/parts/header.html.j2:154
#: amt/site/templates/pages/landingpage.html.j2:16
#: amt/site/templates/parts/header.html.j2:103
#: amt/site/templates/parts/header.html.j2:161
msgid "Login"
msgstr ""

Expand Down Expand Up @@ -275,6 +302,7 @@ msgstr ""
msgid "AMT Placeholder informatie pagina's"
msgstr ""

#: amt/site/templates/pages/landingpage.html.j2:12
#: amt/site/templates/parts/footer.html.j2:4
#: amt/site/templates/parts/header.html.j2:8
msgid "Algorithm Management Toolkit"
Expand Down Expand Up @@ -306,16 +334,6 @@ msgstr ""
msgid "Everyone is welcome to make comments and suggestions."
msgstr ""

#: amt/site/templates/parts/header.html.j2:88
#: amt/site/templates/parts/header.html.j2:143
msgid "Language"
msgstr ""

#: amt/site/templates/parts/header.html.j2:109
#: amt/site/templates/parts/header.html.j2:162
msgid "Logout"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:3
#: amt/site/templates/projects/details_data.html.j2:3
#: amt/site/templates/projects/details_info.html.j2:3
Expand Down Expand Up @@ -448,3 +466,6 @@ msgstr ""
msgid "Copy results and close"
msgstr ""

#~ msgid "Algortime Management Toolkit"
#~ msgstr ""

Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
47 changes: 34 additions & 13 deletions amt/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ msgstr "Start"
msgid "Projects"
msgstr "Projecten"

#: amt/api/navigation.py:47
#: amt/api/navigation.py:47 amt/site/templates/auth/profile.html.j2:10
msgid "Overview"
msgstr "Overzicht"

Expand Down Expand Up @@ -194,6 +194,32 @@ msgstr ""
"Er is iets fout gegaan tijdens de autorisatiestroom. Probeer het later "
"opnieuw"

#: amt/site/templates/auth/profile.html.j2:10
msgid "of"
msgstr "van"

#: amt/site/templates/auth/profile.html.j2:18
msgid "Logout"
msgstr "Uitloggen"

#: amt/site/templates/auth/profile.html.j2:30
msgid "Edit image"
msgstr "Afbeelding aanpassen"

#: amt/site/templates/auth/profile.html.j2:34
msgid "Name"
msgstr "Naam"

#: amt/site/templates/auth/profile.html.j2:37
msgid "Email"
msgstr "Email"

#: amt/site/templates/auth/profile.html.j2:40
#: amt/site/templates/parts/header.html.j2:92
#: amt/site/templates/parts/header.html.j2:151
msgid "Language"
msgstr "Taal"

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:5
msgid "Not logged in"
msgstr "Niet ingelogd"
Expand All @@ -203,8 +229,9 @@ msgid "Please login to view this page"
msgstr "Meld u aan om deze pagina te bekijken"

#: amt/site/templates/errors/AMTAuthorizationError_401.html.j2:11
#: amt/site/templates/parts/header.html.j2:100
#: amt/site/templates/parts/header.html.j2:154
#: amt/site/templates/pages/landingpage.html.j2:16
#: amt/site/templates/parts/header.html.j2:103
#: amt/site/templates/parts/header.html.j2:161
msgid "Login"
msgstr "Inloggen"

Expand Down Expand Up @@ -283,6 +310,7 @@ msgstr "Antwoord"
msgid "AMT Placeholder informatie pagina's"
msgstr "AMT Placeholder informatie pagina's"

#: amt/site/templates/pages/landingpage.html.j2:12
#: amt/site/templates/parts/footer.html.j2:4
#: amt/site/templates/parts/header.html.j2:8
msgid "Algorithm Management Toolkit"
Expand Down Expand Up @@ -314,16 +342,6 @@ msgstr "Deze website is in ontwikkeling. Alle versies ontstaan op een open manie
msgid "Everyone is welcome to make comments and suggestions."
msgstr "Iedereen mag opmerkingen en suggesties doen."

#: amt/site/templates/parts/header.html.j2:88
#: amt/site/templates/parts/header.html.j2:143
msgid "Language"
msgstr "Taal"

#: amt/site/templates/parts/header.html.j2:109
#: amt/site/templates/parts/header.html.j2:162
msgid "Logout"
msgstr "Uitloggen"

#: amt/site/templates/projects/details_base.html.j2:3
#: amt/site/templates/projects/details_data.html.j2:3
#: amt/site/templates/projects/details_info.html.j2:3
Expand Down Expand Up @@ -461,3 +479,6 @@ msgstr "Maak project"
msgid "Copy results and close"
msgstr "Resultaten overnemen en sluiten"

#~ msgid "Algortime Management Toolkit"
#~ msgstr "Algoritme Management Toolkit"

5 changes: 2 additions & 3 deletions amt/middleware/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import Response
from starlette.responses import RedirectResponse, Response

from amt.core.authorization import get_user
from amt.core.exceptions import AMTAuthorizationError

RequestResponseEndpoint = typing.Callable[[Request], typing.Awaitable[Response]]

Expand All @@ -30,4 +29,4 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
if auth_disable:
return response

raise AMTAuthorizationError()
return RedirectResponse(url="/")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions amt/site/templates/auth/profile.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'layouts/base.html.j2' %}
{% block content %}
{% set language_mappings = {"nl": "Nederlands", "en": "English"} %}
<div class="rvo-max-width-layout rvo-max-width-layout--md rvo-max-width-layout-inline-padding--none">
<div class="rvo-content" style="margin-block-start: 3em;">
<div class="profile-header-container"
style="display: flex;
justify-content: space-between">
<h1 class="utrecht-heading-1 rvo-heading--no-margins rvo-heading--mixed --rvo-space-sm">
<strong>{% trans %}Overview{% endtrans %}</strong> {% trans %}of{% endtrans %} {{ user['name'] }}
</h1>
<a href="/auth/logout">
<button class="utrecht-button utrecht-button--secondary-action utrecht-button--rvo-md"
type="button">
<span class="utrecht-icon rvo-icon rvo-icon-versleutelen rvo-icon--md rvo-icon--hemelblauw"
role="img"
aria-label="Logout"></span>
{% trans %}Logout{% endtrans %}
</button>
</a>
</div>
<div style="position: relative">
<img style="display: block"
width="128"
height="128"
src="https://gravatar.com/avatar/{{ user['email_hash'] }}?r=g&s=256&d=https%3A%2F%2Fui-avatars.com%2Fapi%2F/{{ user['name_encoded'] }}/256"
alt="User icon">
<a href="https://gravatar.com/"
target="_blank"
class="rvo-link rvo-link--with-icon rvo-link--no-underline">{% trans %}Edit image{% endtrans %}</a>
</div>
<ul class="rvo-item-list" style="margin-block-start: 1em;">
<li class="rvo-item-list__item">
<strong style="width: 12em; display: inline-block">{% trans %}Name{% endtrans %}</strong>{{ user['name'] }}
</li>
<li class="rvo-item-list__item">
<strong style="width: 12em; display: inline-block">{% trans %}Email{% endtrans %}</strong>{{ user['email'] }}
</li>
<li class="rvo-item-list__item">
<strong style="width: 12em; display: inline-block">{% trans %}Language{% endtrans %}</strong>{{ language_mappings.get(user['locale']) }}
</li>
</ul>
</div>
</div>
{% endblock %}
35 changes: 26 additions & 9 deletions amt/site/templates/pages/landingpage.html.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
{% extends 'layouts/base.html.j2' %}
{% block content %}
<div class="rvo-max-width-layout rvo-max-width-layout--md rvo-max-width-layout-inline-padding--none">
<div style="text-align: center">
<span style="inline-size: 150px;
block-size: 150px"
class="utrecht-icon rvo-icon rvo-icon-computer rvo-icon--xl rvo-icon--hemelblauw"
role="img"
aria-label="Delta naar rechts"></span>
<div class="rvo-content">
<div class="rvo-hero">
<div class="rvo-hero__image-container">
<img src="static/images/berichtenbox-bedrijven.jpg"
class="rvo-hero__image"
alt="" />
</div>
<h1 class="rvo-hero__title utrecht-heading-1">
{% trans %}Algorithm Management Toolkit{% endtrans %}
<br>
<a href="/auth/login"
class="utrecht-button utrecht-button--secondary-action utrecht-button--rvo-md rvo-hero__subtitle rvo-link--no-underline"
type="button">{% trans %}Login{% endtrans %}</a>
</h1>
</div>
<div class="rvo-max-width-layout rvo-max-width-layout--md"
style="padding: 1.5em">
<h3 class="utrecht-heading-3">lorem ipsum dolor sit amet</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Praesentium, minus quia fuga temporibus aspernatur optio doloribus nisi iusto, provident dolore velit ratione quam dicta pariatur consequuntur, ipsa reprehenderit accusantium in.
</p>
<p style="margin-block-start: 1.5em">
A, ipsa distinctio molestias exercitationem corporis eum ea molestiae temporibus sequi doloremque amet officia ullam dolore earum! Illum dolores ipsa necessitatibus excepturi ex reprehenderit ad cupiditate. Aperiam rerum esse id?
</p>
</div>
</div>
<p>
De Algoritme Management Toolkit is ... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam accumsan eros at nisi volutpat, at sagittis ipsum sodales. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean cursus, enim ac sollicitudin vestibulum, ante urna sollicitudin ex, ut mollis neque ipsum nec dui. Vestibulum maximus sapien euismod nulla commodo, et dignissim augue tempus. Morbi eleifend lacus in augue semper, at condimentum purus luctus. Nullam vel dolor lorem. Nam cursus tincidunt lacus, ut pharetra tortor cursus et. Etiam eu tortor at neque convallis imperdiet.
</p>
</div>
</div>
{% endblock %}
Loading

0 comments on commit 46a9006

Please sign in to comment.