stages/identification: add more templates

This commit is contained in:
Jens Langhammer 2020-05-10 20:17:10 +02:00
parent a67c53f46a
commit 206cf4967d
6 changed files with 105 additions and 11 deletions

View File

@ -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,
},

View File

@ -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:

View File

@ -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"),
]
),
),
]

View File

@ -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):

View File

@ -0,0 +1 @@
{% extends 'login/form.html' %}

View File

@ -0,0 +1,68 @@
{% extends 'base/skeleton.html' %}
{% load static %}
{% load i18n %}
{% block body %}
<div class="pf-c-background-image">
<svg xmlns="http://www.w3.org/2000/svg" class="pf-c-background-image__filter" width="0" height="0">
<filter id="image_overlay">
<feColorMatrix type="matrix" values="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0"></feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
<feFuncR type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncR>
<feFuncG type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncG>
<feFuncB type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
</div>
{% include 'partials/messages.html' %}
<div class="pf-c-login">
<div class="pf-c-login__container">
<header class="pf-c-login__header">
<img class="pf-c-brand" src="{% static 'passbook/logo.svg' %}" style="height: 60px;"
alt="passbook icon" />
<img class="pf-c-brand" src="{% static 'passbook/brand.svg' %}" style="height: 60px;"
alt="passbook branding" />
</header>
<main class="pf-c-login__main">
<header class="pf-c-login__main-header">
<h1 class="pf-c-title pf-m-3xl">
{% trans 'Trouble Logging In?' %}
</h1>
</header>
<div class="pf-c-login__main-body">
{% block card %}
<form method="POST" class="pf-c-form">
{% block above_form %}
{% endblock %}
{% include 'partials/form.html' %}
{% block beneath_form %}
{% endblock %}
<div class="pf-c-form__group pf-m-action">
<button class="pf-c-button pf-m-primary pf-m-block" type="submit">{% trans primary_action %}</button>
</div>
</form>
{% endblock %}
</div>
<footer class="pf-c-login__main-footer">
{% if config.login.subtext %}
<p>{{ config.login.subtext }}</p>
{% endif %}
</footer>
</main>
<footer class="pf-c-login__footer">
<p></p>
<ul class="pf-c-list pf-m-inline">
<li>
<a href="https://beryju.github.io/passbook/">{% trans 'Documentation' %}</a>
</li>
<!-- TODO: load config.passbook.footer.links -->
</ul>
</footer>
</div>
</div>
{% endblock %}