From 33431ae0133c9f9fb097dfbee9a023cf189bbba3 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 25 Feb 2019 14:10:10 +0100 Subject: [PATCH] improve OAuth Source Setup process, fix login template, closes #3 --- .../templates/administration/source/list.html | 2 + passbook/core/models.py | 9 +- passbook/core/templates/login/base.html | 8 +- passbook/core/templates/login/form.html | 1 - passbook/core/templates/login/test.html | 131 ------------------ .../core/templates/login/with_sources.html | 98 ++++++++----- passbook/core/views/authentication.py | 9 +- passbook/oauth_client/models.py | 14 +- 8 files changed, 93 insertions(+), 179 deletions(-) delete mode 100644 passbook/core/templates/login/test.html diff --git a/passbook/admin/templates/administration/source/list.html b/passbook/admin/templates/administration/source/list.html index 2d7c6c545..f87bd176a 100644 --- a/passbook/admin/templates/administration/source/list.html +++ b/passbook/admin/templates/administration/source/list.html @@ -27,6 +27,7 @@ {% trans 'Name' %} {% trans 'Class' %} + {% trans 'Additional Info' %} @@ -35,6 +36,7 @@ {{ source.name }} {{ source|fieldtype }} + {{ source.additional_info }} {% trans 'Edit' %} diff --git a/passbook/core/models.py b/passbook/core/models.py index ab8283afc..f06345380 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -155,10 +155,15 @@ class Source(PolicyModel): return False @property - def get_url(self): - """Return URL used for logging in""" + def get_login_button(self): + """Return a tuple of URL, Icon name and Name""" raise NotImplementedError + @property + def additional_info(self): + """Return additional Info, such as a callback URL. Show in the administration interface.""" + return None + def __str__(self): return self.name diff --git a/passbook/core/templates/login/base.html b/passbook/core/templates/login/base.html index 429f90c62..42ecaf5b4 100644 --- a/passbook/core/templates/login/base.html +++ b/passbook/core/templates/login/base.html @@ -23,16 +23,16 @@ {% endblock %} {% block body %} +
+ {% include 'partials/messages.html' with toast=True %} +
-
- {% include 'partials/messages.html' %} -
- {% csrf_token %} {% block above_form %} {% endblock %} {% include 'partials/form_login.html' %} diff --git a/passbook/core/templates/login/test.html b/passbook/core/templates/login/test.html deleted file mode 100644 index 9dc470f0c..000000000 --- a/passbook/core/templates/login/test.html +++ /dev/null @@ -1,131 +0,0 @@ -{% load static %} - - - - - - - Login Social Account (two column) - Red Hat® Common User Experience - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - These examples are included for development testing purposes. For official documentation, see https://www.patternfly.org and http://getbootstrap.com. -
-
- - -
- - - - - diff --git a/passbook/core/templates/login/with_sources.html b/passbook/core/templates/login/with_sources.html index a3435b932..ba744b8cb 100644 --- a/passbook/core/templates/login/with_sources.html +++ b/passbook/core/templates/login/with_sources.html @@ -1,51 +1,79 @@ -{% extends 'login/base.html' %} +{% extends 'base/skeleton.html' %} {% load static %} {% load i18n %} -{% block row %} -{% include 'partials/messages.html' %} -
-
+{% block head %} + +{% endblock %} + +{% block body %} +
+ {% include 'partials/messages.html' with toast=True %} +
+ -
-
- -
-
- {% endblock %} diff --git a/passbook/core/views/authentication.py b/passbook/core/views/authentication.py index b2d4d47df..0dad352db 100644 --- a/passbook/core/views/authentication.py +++ b/passbook/core/views/authentication.py @@ -42,9 +42,12 @@ class LoginView(UserPassesTestMixin, FormView): kwargs['primary_action'] = _('Log in') kwargs['show_sign_up_notice'] = CONFIG.y('passbook.sign_up.enabled') kwargs['show_password_forget_notice'] = CONFIG.y('passbook.password_reset.enabled') - kwargs['sources'] = Source.objects.filter(enabled=True).select_subclasses() - if any(source.is_link for source in kwargs['sources']): - self.template_name = 'login/test.html' + kwargs['sources'] = [] + sources = Source.objects.filter(enabled=True).select_subclasses() + if any(source.is_link for source in sources): + for source in sources: + kwargs['sources'].append(source.get_login_button) + self.template_name = 'login/with_sources.html' return super().get_context_data(**kwargs) def get_user(self, uid_value) -> User: diff --git a/passbook/oauth_client/models.py b/passbook/oauth_client/models.py index c34781974..d7eb37fac 100644 --- a/passbook/oauth_client/models.py +++ b/passbook/oauth_client/models.py @@ -26,9 +26,17 @@ class OAuthSource(Source): return True @property - def get_url(self): - return reverse_lazy('passbook_oauth_client:oauth-client-login', - kwargs={'source_slug': self.slug}) + def get_login_button(self): + url = reverse_lazy('passbook_oauth_client:oauth-client-login', + kwargs={'source_slug': self.slug}) + if self.provider_type == 'github': + return url, 'github-logo', _('GitHub') + return url, 'generic', _('Generic') + + @property + def additional_info(self): + return "Callback URL: '%s'" % reverse_lazy('passbook_oauth_client:oauth-client-callback', + kwargs={'source_slug': self.slug}) class Meta: