From 1052750f7337db28119cc18dbd009421c61284b8 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 29 May 2023 18:30:51 +0200 Subject: [wip] add ability to re-send the verification mail --- fietsboek/routes.py | 1 + fietsboek/templates/login.jinja2 | 2 + fietsboek/templates/resend_verification.jinja2 | 22 +++++++++++ fietsboek/views/default.py | 51 ++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 fietsboek/templates/resend_verification.jinja2 diff --git a/fietsboek/routes.py b/fietsboek/routes.py index 8f109d9..60a566d 100644 --- a/fietsboek/routes.py +++ b/fietsboek/routes.py @@ -14,6 +14,7 @@ def includeme(config): config.add_route("track-archive", "/track/archive") config.add_route("password-reset", "/password-reset") + config.add_route("resend-verification", "/resend-verification") config.add_route("use-token", "/token/{uuid}") config.add_route("create-account", "/create-account") diff --git a/fietsboek/templates/login.jinja2 b/fietsboek/templates/login.jinja2 index 7a9bf07..bdf2c99 100644 --- a/fietsboek/templates/login.jinja2 +++ b/fietsboek/templates/login.jinja2 @@ -41,6 +41,8 @@
diff --git a/fietsboek/templates/resend_verification.jinja2 b/fietsboek/templates/resend_verification.jinja2 new file mode 100644 index 0000000..cc56854 --- /dev/null +++ b/fietsboek/templates/resend_verification.jinja2 @@ -0,0 +1,22 @@ +{% extends "layout.jinja2" %} +{% import "util.jinja2" as util with context %} +{% block content %} +
+

{{ _("page.resend_verification.title") }}

+

{{ _("page.resend_verification.info") }}

+
+
+
+
+ + +
+
+ {{ util.hidden_csrf_input() }} +
+ +
+
+
+
+{% endblock %} diff --git a/fietsboek/views/default.py b/fietsboek/views/default.py index b8b1835..397f9ca 100644 --- a/fietsboek/views/default.py +++ b/fietsboek/views/default.py @@ -196,6 +196,57 @@ def do_password_reset(request: Request) -> Response: return HTTPFound(request.route_url("password-reset")) +@view_config( + route_name="resend-verification", + request_method="GET", + renderer="fietsboek:templates/resend_verification.jinja2", +) +def resend_verification(request: Request) -> Response: + """Form to request a new verification mail. + + :param request: The Pyramid request. + :return: The HTTP response. + """ + return {} + + +@view_config(route_name="resend-verification", request_method="POST") +def do_resend_verification(request: Request) -> Response: + """Endpoint for the verification resend form. + + :param request: The Pyramid request. + :return: The HTTP response. + """ + query = models.User.query_by_email(request.params["email"]) + user = request.dbsession.execute(query).scalar_one_or_none() + if user is None or user.is_verified: + request.session.flash(request.localizer.translate(_("flash.resend_verification_email"))) + return HTTPFound(request.route_url("resend-verification")) + + token = models.Token.generate(user, TokenType.VERIFY_EMAIL) + request.dbsession.add(token) + request.session.flash(request.localizer.translate(_("flash.verification_token_generated"))) + + mail = email.prepare_message( + request.config.email_from, + user.email, + request.localizer.translate(_("page.password_reset.email.subject")), + ) + mail.set_content( + request.localizer.translate(_("page.password_reset.email.body")).format( + request.route_url("use-token", uuid=token.uuid) + ) + ) + email.send_message( + request.config.email_smtp_url, + request.config.email_username, + request.config.email_password.get_secret_value(), + mail, + ) + + return HTTPFound(request.route_url("password-reset")) + + @view_config(route_name="use-token") def use_token(request: Request) -> Response: """Endpoint with which a user can use a token for a password reset or email -- cgit v1.2.3