diff --git a/passbook/stages/email/stage.py b/passbook/stages/email/stage.py index 76cb97726..10c2a0891 100644 --- a/passbook/stages/email/stage.py +++ b/passbook/stages/email/stage.py @@ -1,10 +1,10 @@ """passbook multi-stage authentication engine""" from datetime import timedelta -from urllib.parse import quote from django.contrib import messages from django.http import HttpRequest from django.shortcuts import reverse +from django.utils.http import urlencode from django.utils.timezone import now from django.utils.translation import gettext as _ from structlog import get_logger @@ -23,6 +23,15 @@ class EmailStageView(AuthenticationStage): template_name = "stages/email/waiting_message.html" + def get_full_url(self, **kwargs) -> str: + """Get full URL to be used in template""" + base_url = reverse( + "passbook_flows:flow-executor", + kwargs={"flow_slug": self.executor.flow.slug}, + ) + relative_url = f"{base_url}?{urlencode(kwargs)}" + return self.request.build_absolute_uri(relative_url) + def get(self, request, *args, **kwargs): # TODO: Form to make sure email is only sent once pending_user = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER] @@ -37,14 +46,7 @@ class EmailStageView(AuthenticationStage): template_name="stages/email/for_email/password_reset.html", to=[pending_user.email], template_context={ - "url": self.request.build_absolute_uri( - reverse( - "passbook_flows:flow-executor", - kwargs={"flow_slug": self.executor.flow.slug}, - ) - + "?token=" - + quote(nonce.uuid.hex) - ), + "url": self.get_full_url(token=nonce.pk.hex), "user": pending_user, "expires": nonce.expires, }, diff --git a/passbook/stages/email/utils.py b/passbook/stages/email/utils.py index e46f27d7d..b26b9eab6 100644 --- a/passbook/stages/email/utils.py +++ b/passbook/stages/email/utils.py @@ -7,7 +7,6 @@ from django.utils.html import strip_tags class TemplateEmailMessage(EmailMultiAlternatives): """Wrapper around EmailMultiAlternatives with integrated template rendering""" - # pylint: disable=too-many-arguments def __init__(self, template_name=None, template_context=None, **kwargs): html_content = render_to_string(template_name, template_context) if "body" not in kwargs: diff --git a/passbook/stages/identification/migrations/0004_auto_20200510_1648.py b/passbook/stages/identification/migrations/0004_auto_20200510_1648.py new file mode 100644 index 000000000..9c081b969 --- /dev/null +++ b/passbook/stages/identification/migrations/0004_auto_20200510_1648.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.5 on 2020-05-10 16:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_stages_identification", "0003_auto_20200509_2025"), + ] + + operations = [ + migrations.AlterField( + model_name="identificationstage", + name="template", + field=models.TextField( + choices=[ + ("stages/identification/login.html", "Default Login"), + ("stages/identification/recovery.html", "Default Recovery"), + ] + ), + ), + ] diff --git a/passbook/stages/identification/models.py b/passbook/stages/identification/models.py index 40616d0ac..d43b6b15c 100644 --- a/passbook/stages/identification/models.py +++ b/passbook/stages/identification/models.py @@ -16,7 +16,8 @@ class UserFields(models.TextChoices): class Templates(models.TextChoices): """Templates to be used for the stage""" - DEFAULT_LOGIN = "login/form.html" + DEFAULT_LOGIN = "stages/identification/login.html" + DEFAULT_RECOVERY = "stages/identification/recovery.html" class IdentificationStage(Stage): diff --git a/passbook/stages/identification/templates/stages/identification/login.html b/passbook/stages/identification/templates/stages/identification/login.html new file mode 100644 index 000000000..640765f1e --- /dev/null +++ b/passbook/stages/identification/templates/stages/identification/login.html @@ -0,0 +1 @@ +{% extends 'login/form.html' %} diff --git a/passbook/stages/identification/templates/stages/identification/recovery.html b/passbook/stages/identification/templates/stages/identification/recovery.html new file mode 100644 index 000000000..1cf4c4838 --- /dev/null +++ b/passbook/stages/identification/templates/stages/identification/recovery.html @@ -0,0 +1,68 @@ +{% extends 'base/skeleton.html' %} + +{% load static %} +{% load i18n %} + +{% block body %} +
+ + + + + + + + + + + +
+{% include 'partials/messages.html' %} +
+
+ +
+ + +
+ {% if config.login.subtext %} +

{{ config.login.subtext }}

+ {% endif %} +
+
+ +
+
+{% endblock %}