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> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% if show_sign_up_notice %} {% if enroll_url %}
<div class="pf-c-login__main-footer-band"> <div class="pf-c-login__main-footer-band">
<p class="pf-c-login__main-footer-band-item"> <p class="pf-c-login__main-footer-band-item">
{% trans 'Need an account?' %} {% 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> </p>
</div> </div>
{% endif %} {% endif %}

View File

@ -56,6 +56,11 @@ class Flow(PolicyBindingModel, UUIDModel):
PolicyBindingModel, parent_link=True, on_delete=models.CASCADE, related_name="+" 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: def __str__(self) -> str:
return f"Flow {self.name} ({self.slug})" return f"Flow {self.name} ({self.slug})"

View File

@ -19,9 +19,6 @@ error_reporting: false
domain: localhost domain: localhost
passbook: 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: password_reset:
# Enable password reset, passwords are reset in internal Database and in LDAP if ldap.reset_password is true # Enable password reset, passwords are reset in internal Database and in LDAP if ldap.reset_password is true
enabled: true enabled: true
@ -30,7 +27,3 @@ passbook:
# Optionally add links to the footer on the login page # Optionally add links to the footer on the login page
# - name: test # - name: test
# href: https://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.contrib import messages
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import reverse
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import FormView from django.views.generic import FormView
from structlog import get_logger from structlog import get_logger
from passbook.core.models import Source, User 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.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import AuthenticationStage from passbook.flows.stage import AuthenticationStage
from passbook.lib.config import CONFIG
from passbook.stages.identification.forms import IdentificationForm from passbook.stages.identification.forms import IdentificationForm
from passbook.stages.identification.models import IdentificationStage from passbook.stages.identification.models import IdentificationStage
@ -33,11 +34,16 @@ class IdentificationStageView(FormView, AuthenticationStage):
return [current_stage.template] return [current_stage.template]
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs["config"] = CONFIG.y("passbook") # Check for related enrollment flow, add URL to view
kwargs["title"] = _("Log in to your account") enrollment_flow = self.executor.flow.related_flow(FlowDesignation.ENROLLMENT)
kwargs["primary_action"] = _("Log in") if enrollment_flow:
# TODO: show this based on the existence of an enrollment flow url = reverse(
kwargs["show_sign_up_notice"] = CONFIG.y("passbook.sign_up.enabled") "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"] = [] kwargs["sources"] = []
sources = ( sources = (
Source.objects.filter(enabled=True).order_by("name").select_subclasses() Source.objects.filter(enabled=True).order_by("name").select_subclasses()