stages/identification: add recovery support

This commit is contained in:
Jens Langhammer 2020-05-10 18:45:16 +02:00
parent 2ffa2fc6b8
commit a7567ad8c6
3 changed files with 35 additions and 5 deletions

View file

@ -63,12 +63,21 @@
</li>
{% endfor %}
</ul>
{% if enroll_url %}
{% if enroll_url or recovery_url %}
<div class="pf-c-login__main-footer-band">
{% if enroll_url %}
<p class="pf-c-login__main-footer-band-item">
{% trans 'Need an account?' %}
<a href="{{ enroll_url }}">{% trans 'Sign up.' %}</a>
</p>
{% endif %}
{% if recovery_url %}
<p class="pf-c-login__main-footer-band-item">
<a href="{{ recovery_url }}">
{% trans 'Forgot username or password?' %}
</a>
</p>
{% endif %}
</div>
{% endif %}
</footer>

View file

@ -34,14 +34,19 @@ class IdentificationStageView(FormView, AuthenticationStage):
return [current_stage.template]
def get_context_data(self, **kwargs):
# Check for related enrollment flow, add URL to view
# Check for related enrollment and recovery flow, add URL to view
enrollment_flow = self.executor.flow.related_flow(FlowDesignation.ENROLLMENT)
if enrollment_flow:
url = reverse(
kwargs["enroll_url"] = reverse(
"passbook_flows:flow-executor",
kwargs={"flow_slug": enrollment_flow.slug},
)
kwargs["enroll_url"] = url
recovery_flow = self.executor.flow.related_flow(FlowDesignation.RECOVERY)
if recovery_flow:
kwargs["recovery_url"] = reverse(
"passbook_flows:flow-executor",
kwargs={"flow_slug": recovery_flow.slug},
)
# Check all enabled source, add them if they have a UI Login button.
kwargs["sources"] = []

View file

@ -82,7 +82,7 @@ class TestIdentificationStage(TestCase):
"""Test that enrollment flow is linked correctly"""
flow = Flow.objects.create(
name="enroll-test",
slug="unique-string",
slug="unique-enrollment-string",
designation=FlowDesignation.ENROLLMENT,
)
@ -93,3 +93,19 @@ class TestIdentificationStage(TestCase):
)
self.assertEqual(response.status_code, 200)
self.assertIn(flow.slug, response.rendered_content)
def test_recovery_flow(self):
"""Test that recovery flow is linked correctly"""
flow = Flow.objects.create(
name="enroll-test",
slug="unique-recovery-string",
designation=FlowDesignation.RECOVERY,
)
response = self.client.get(
reverse(
"passbook_flows:flow-executor", kwargs={"flow_slug": self.flow.slug}
),
)
self.assertEqual(response.status_code, 200)
self.assertIn(flow.slug, response.rendered_content)