stages/identification: show sign up url when related flow exists

This commit is contained in:
Jens Langhammer 2020-05-10 18:14:10 +02:00
parent 8dc3c49a2f
commit 1d03b36750
4 changed files with 19 additions and 15 deletions

View file

@ -63,11 +63,11 @@
</li>
{% endfor %}
</ul>
{% if show_sign_up_notice %}
{% if enroll_url %}
<div class="pf-c-login__main-footer-band">
<p class="pf-c-login__main-footer-band-item">
{% trans 'Need an account?' %}
<a href="{% url 'passbook_core:auth-sign-up' %}">{% trans 'Sign up.' %}</a>
<a href="{{ enroll_url }}">{% trans 'Sign up.' %}</a>
</p>
</div>
{% endif %}

View file

@ -56,6 +56,11 @@ class Flow(PolicyBindingModel, UUIDModel):
PolicyBindingModel, parent_link=True, on_delete=models.CASCADE, related_name="+"
)
def related_flow(self, designation: str) -> Optional["Flow"]:
"""Get a related flow with `designation`. Currently this only queries
Flows by `designation`, but will eventually use `self` for related lookups."""
return Flow.objects.filter(designation=designation).first()
def __str__(self) -> str:
return f"Flow {self.name} ({self.slug})"

View file

@ -19,9 +19,6 @@ error_reporting: false
domain: localhost
passbook:
sign_up:
# Enables signup, created users are stored in internal Database and created in LDAP if ldap.create_users is true
enabled: true
password_reset:
# Enable password reset, passwords are reset in internal Database and in LDAP if ldap.reset_password is true
enabled: true
@ -30,7 +27,3 @@ passbook:
# Optionally add links to the footer on the login page
# - name: test
# href: https://test
# Specify which fields can be used to authenticate. Can be any combination of `username` and `email`
uid_fields:
- username
- email

View file

@ -4,14 +4,15 @@ from typing import List, Optional
from django.contrib import messages
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import reverse
from django.utils.translation import gettext as _
from django.views.generic import FormView
from structlog import get_logger
from passbook.core.models import Source, User
from passbook.flows.models import FlowDesignation
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage
from passbook.lib.config import CONFIG
from passbook.stages.identification.forms import IdentificationForm
from passbook.stages.identification.models import IdentificationStage
@ -33,11 +34,16 @@ class IdentificationStageView(FormView, AuthenticationStage):
return [current_stage.template]
def get_context_data(self, **kwargs):
kwargs["config"] = CONFIG.y("passbook")
kwargs["title"] = _("Log in to your account")
kwargs["primary_action"] = _("Log in")
# TODO: show this based on the existence of an enrollment flow
kwargs["show_sign_up_notice"] = CONFIG.y("passbook.sign_up.enabled")
# Check for related enrollment flow, add URL to view
enrollment_flow = self.executor.flow.related_flow(FlowDesignation.ENROLLMENT)
if enrollment_flow:
url = reverse(
"passbook_flows:flow-executor",
kwargs={"flow_slug": enrollment_flow.slug},
)
kwargs["enroll_url"] = url
# Check all enabled source, add them if they have a UI Login button.
kwargs["sources"] = []
sources = (
Source.objects.filter(enabled=True).order_by("name").select_subclasses()