diff --git a/InvenTree/part/templatetags/sso.py b/InvenTree/part/templatetags/sso.py new file mode 100644 index 0000000000..2bcbf5f606 --- /dev/null +++ b/InvenTree/part/templatetags/sso.py @@ -0,0 +1,48 @@ +"""This module provides template tags pertaining to SSO functionality""" + + +from django import template + +from common.models import InvenTreeSetting +from InvenTree.helpers import str2bool + +register = template.Library() + + +@register.simple_tag() +def sso_login_enabled(): + """Return True if single-sign-on is enabled""" + + val = InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO') + + print("SSO Enabled:", val) + + return str2bool(InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO')) + + +@register.simple_tag() +def sso_reg_enabled(): + """Return True if single-sign-on is enabled for self-registration""" + return str2bool(InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO_REG')) + + +@register.simple_tag() +def sso_auto_enabled(): + """Return True if single-sign-on is enabled for auto-registration""" + return str2bool(InvenTreeSetting.get_setting('LOGIN_SIGNUP_SSO_AUTO')) + + +@register.simple_tag() +def sso_check_provider(provider): + """Return True if the given provider is correctly configured""" + + from allauth.socialaccount.models import SocialApp + + # First, check that the provider is enabled + if not SocialApp.objects.filter(provider__iexact=provider.name).exists(): + return False + + # Next, check that the provider is correctly configured + + # At this point, we assume that the provider is correctly configured + return True diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index ca1c1fdc18..9a1fbcd135 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -1,6 +1,7 @@ {% extends "panel.html" %} {% load i18n %} +{% load sso %} {% load inventree_extras %} {% load socialaccount %} {% load crispy_forms_tags %} @@ -112,62 +113,7 @@ {% endif %} -
{% blocktrans %}You can sign in to your account using any of the following third party accounts:{% endblocktrans %}
- - - - - {% else %} -{% blocktrans %}You can sign in to your account using any of the following third party accounts:{% endblocktrans %}
+ + + + + {% else %} +{% blocktrans with provider.name as provider %}You are about to connect a new third party account from {{ provider }}.{% endblocktrans %}
{% else %} -{% blocktrans with provider.name as provider %}You are about to sign in using a third party account from {{ provider }}.{% endblocktrans %}
{% endif %} @@ -19,10 +24,19 @@ +{% else %} ++ {% trans "The selected SSO provider is invalid, or has not been correctly configured" %} +
+