Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show/buttons by authentication #715

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.template.loader import render_to_string
from django.test import SimpleTestCase

class TestWizardActionsTemplate(SimpleTestCase):
def test_render_template_authenticated(self):
template_name = 'two_factor/_wizard_actions.html'

# Render the template
rendered_template = self.render_template(template_name, {'user': {'is_authenticated': True}, 'cancel_url': '/cancel', 'wizard': {'steps': {'prev': 'previous_step'}}})

# Assert that the "Sign in" button is not present for authenticated users
self.assertNotIn('<button type="submit" name="login" class="btn btn-dark">Sign in</button>', rendered_template)

def test_render_template_not_authenticated(self):
template_name = 'two_factor/_wizard_actions.html'

# Render the template
rendered_template = self.render_template(template_name, {'user': {'is_authenticated': False}})

# Assert that the "Sign in" button is present for non-authenticated users
self.assertIn('Sign in', rendered_template)

def render_template(self, template_name, context):
# Render the template with the context
return render_to_string(template_name, context)
29 changes: 20 additions & 9 deletions two_factor/templates/two_factor/_wizard_actions.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
{% load i18n %}

{% if cancel_url %}
<a href="{{ cancel_url }}"
class="float-right btn btn-link">{% trans "Cancel" %}</a>
{% if user.is_authenticated %}
{% if cancel_url %}
<a href="{{ cancel_url }}" class="float-right btn btn-link">{% trans "Cancel" %}</a>
{% endif %}
{% if wizard.steps.prev %}
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}" class="btn btn-secondary">
{% trans "Back" %}
</button>
{% else %}
<button disabled type="button" class="btn btn-secondary">{% trans "Back" %}</button>
{% endif %}
<button type="submit" class="btn btn-primary">{% trans "Next" %}</button>
{% endif %}
{% if wizard.steps.prev %}
<button name="wizard_goto_step" type="submit"
value="{{ wizard.steps.prev }}"
class="btn btn-secondary">{% trans "Back" %}</button>

{% if user.is_authenticated %}
{# User is authenticated, don't show the "Sign in" button #}
{% else %}
<button disabled name="" type="button" class="btn">{% trans "Back" %}</button>
<div class="d-grid mt-3">
<button type="submit" name="login" class="btn btn-dark">
{% trans "Sign in" %}
</button>
</div>
{% endif %}
<button type="submit" class="btn btn-primary">{% trans "Next" %}</button>