aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-01 03:06:11 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-01 03:06:11 +0200
commitd080806bba1a2bd48d8a3c2a8011ee057a300a3b (patch)
tree1b5b3b5da1fa04202d34dac5368f20f77940dcd0
parentcb9a0429bbc8c175b4771b5ee8854ee273f327e1 (diff)
downloadfietsboek-d080806bba1a2bd48d8a3c2a8011ee057a300a3b.tar.gz
fietsboek-d080806bba1a2bd48d8a3c2a8011ee057a300a3b.tar.bz2
fietsboek-d080806bba1a2bd48d8a3c2a8011ee057a300a3b.zip
implement personal data change form
-rw-r--r--fietsboek/routes.py1
-rw-r--r--fietsboek/templates/profile.jinja229
-rw-r--r--fietsboek/views/profile.py25
3 files changed, 54 insertions, 1 deletions
diff --git a/fietsboek/routes.py b/fietsboek/routes.py
index 4113913..3f03ae4 100644
--- a/fietsboek/routes.py
+++ b/fietsboek/routes.py
@@ -26,6 +26,7 @@ def includeme(config):
config.add_route('admin-badge-delete', '/admin/delete-badge')
config.add_route('profile', '/me')
+ config.add_route('change-profile', '/me/personal-data')
config.add_route('add-friend', '/me/send-friend-request')
config.add_route('delete-friend', '/me/delete-friend')
config.add_route('accept-friend', '/me/accept-friend')
diff --git a/fietsboek/templates/profile.jinja2 b/fietsboek/templates/profile.jinja2
index bd74aaf..5487b92 100644
--- a/fietsboek/templates/profile.jinja2
+++ b/fietsboek/templates/profile.jinja2
@@ -3,6 +3,35 @@
{% block content %}
<div class="container">
<h1>{{ _("page.my_profile.title") }}</h1>
+
+ <hr>
+
+ <h2>{{ _("page.my_profile.personal_data") }}</h2>
+
+ <form method="POST" action="{{ request.route_path('change-profile') }}">
+ <div class="row mb-3">
+ <label for="inputName" class="col-sm-3 col-form-label">{{ _("page.my_profile.personal_data.name") }}</label>
+ <div class="col-sm-9">
+ <input type="text" class="form-control" id="inputName" name="name" value="{{ user.name }}">
+ </div>
+ </div>
+ <div class="row mb-3">
+ <label for="inputPassword" class="col-sm-3 col-form-label">{{ _("page.my_profile.personal_data.password") }}</label>
+ <div class="col-sm-9">
+ <input type="password" class="form-control" id="inputPassword" name="password">
+ </div>
+ </div>
+ <div class="row mb-3">
+ <label for="repeatPassword" class="col-sm-3 col-form-label">{{ _("page.my_profile.personal_data.repeat_password") }}</label>
+ <div class="col-sm-9">
+ <input type="password" class="form-control" id="repeatPassword" name="repeat-password">
+ </div>
+ </div>
+ <button type="submit" class="btn btn-primary"><i class="bi bi-save"></i> {{ _("page.my_profile.personal_data.save") }}</button>
+ </form>
+
+ <hr>
+
<h2>{{ _("page.my_profile.friends") }}</h2>
<ul class="list-group">
diff --git a/fietsboek/views/profile.py b/fietsboek/views/profile.py
index fe1ae5a..b138bd0 100644
--- a/fietsboek/views/profile.py
+++ b/fietsboek/views/profile.py
@@ -10,7 +10,8 @@ from sqlalchemy import select
from .. import models
-@view_config(route_name='profile', renderer='fietsboek:templates/profile.jinja2', permission='user')
+@view_config(route_name='profile', renderer='fietsboek:templates/profile.jinja2',
+ permission='user', request_method="GET")
def profile(request):
"""Provides the profile overview.
@@ -33,6 +34,28 @@ def profile(request):
}
+@view_config(route_name="change-profile", permission="user", request_method="POST")
+def do_change_profile(request):
+ """Endpoint to change the personal data.
+
+ :param request: The Pyramid request.
+ :type request: pyramid.request.Request
+ :return: The HTTP response.
+ :rtype: pyramid.response.Response
+ """
+ if request.params["password"]:
+ if request.params["password"] != request.params["repeat-password"]:
+ request.session.flash(request.localizer.translate(_("flash.password_mismatch")))
+ return HTTPFound(request.route_url('profile'))
+ request.identity.set_password(request.params["password"])
+ name = request.params["name"]
+ if request.identity.name != name:
+ request.identity.name = name
+ request.session.flash(request.localizer.translate(_("flash.personal_data_updated")))
+ return HTTPFound(request.route_url('profile'))
+
+
+
@view_config(route_name='add-friend', permission='user', request_method='POST')
def do_add_friend(request):
"""Sends a friend request.