Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Render the consent screen in wger's layout

Roland Geiderc44341319ad1
diff --git a/wger/core/templates/idp/oidc/authorization_form.html b/wger/core/templates/idp/oidc/authorization_form.html
new file mode 100644
index 000000000..cfdb410c6
--- /dev/null
+++ b/wger/core/templates/idp/oidc/authorization_form.html
@@ -0,0 +1,50 @@
+{% extends "template.html" %}
+{% load i18n crispy_forms_tags %}
+
+{% comment %}
+ Consent screen of the OAuth2 provider. Overrides allauth's own template,
+ which is styled for its stand-alone entrance layout.
+{% endcomment %}
+
+{% block title %}{% translate "Authorize" %}{% endblock %}
+
+
+{% block header %}
+{% endblock %}
+
+
+{% block template %}
+ <div class="row justify-content-center">
+ <div class="col-lg-6">
+ <div class="card my-4">
+ <div class="card-body p-4">
+ <h2 class="mb-1">{{ client.name }}</h2>
+ {# Keep the string on one line, it has to match allauth's catalog #}
+ <p class="text-muted">
+ {% blocktranslate with client_name=client.name site_name=site.name %}{{ client_name }} wants to access your {{ site_name }} account.{% endblocktranslate %}
+ </p>
+
+ <form method="post" action="{% url 'idp:oidc:authorization' %}" novalidate>
+ {% csrf_token %}
+ {{ form|crispy }}
+
+ <div class="d-flex gap-2 mt-4">
+ <button type="submit"
+ name="action"
+ value="grant"
+ class="btn btn-success w-100">
+ {% translate "Authorize" %}
+ </button>
+ <button type="submit"
+ name="action"
+ value="cancel"
+ class="btn btn-outline-secondary w-100">
+ {% translate "Cancel" %}
+ </button>
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+{% endblock %}
diff --git a/wger/core/tests/test_oidc_provider.py b/wger/core/tests/test_oidc_provider.py
index 1298d037a..36c8812c8 100644
--- a/wger/core/tests/test_oidc_provider.py
+++ b/wger/core/tests/test_oidc_provider.py
@@ -131,6 +131,10 @@ class OidcProviderTestCase(WgerTestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'idp/oidc/authorization_form.html')
+ # allauth's own template renders no action attribute, so this also
+ # asserts that wger's override is the one being used
+ self.assertContains(response, f'action="{reverse("idp:oidc:authorization")}"')
+
response = self.client.post(
reverse('idp:oidc:authorization'),
{