diff --git a/passbook/core/models.py b/passbook/core/models.py index 1c0866a69..ab8283afc 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -74,6 +74,12 @@ class Factor(PolicyModel): type = '' form = '' + def has_user_settings(self): + """Entrypoint to integrate with User settings. Can either return False if no + user settings are available, or a tuple or string, string, string where the first string + is the name the item has, the second string is the icon and the third is the view-name.""" + return False + def __str__(self): return "Factor %s" % self.slug @@ -85,6 +91,9 @@ class PasswordFactor(Factor): type = 'passbook.core.auth.factors.password.PasswordFactor' form = 'passbook.core.forms.factors.PasswordFactorForm' + def has_user_settings(self): + return _('Change Password'), 'pficon-key', 'passbook_core:user-change-password' + def __str__(self): return "Password Factor %s" % self.slug diff --git a/passbook/core/templates/user/base.html b/passbook/core/templates/user/base.html index 5195c50f9..c908aafc3 100644 --- a/passbook/core/templates/user/base.html +++ b/passbook/core/templates/user/base.html @@ -2,25 +2,28 @@ {% load i18n %} {% load is_active %} +{% load passbook_user_settings %} {% block content %}
diff --git a/passbook/core/templatetags/__init__.py b/passbook/core/templatetags/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/core/templatetags/passbook_user_settings.py b/passbook/core/templatetags/passbook_user_settings.py new file mode 100644 index 000000000..9b5ac5372 --- /dev/null +++ b/passbook/core/templatetags/passbook_user_settings.py @@ -0,0 +1,19 @@ +"""passbook user settings template tags""" + +from django import template + +from passbook.core.models import Factor + +register = template.Library() + +@register.simple_tag(takes_context=True) +def user_factors(context): + """Return list of all factors which apply to user""" + user = context.get('request').user + _all_factors = Factor.objects.filter(enabled=True).order_by('order').select_subclasses() + matching_factors = [] + for factor in _all_factors: + _link = factor.has_user_settings() + if factor.passes(user) and _link: + matching_factors.append(_link) + return matching_factors diff --git a/passbook/otp/models.py b/passbook/otp/models.py index e5d03e205..15d2249e7 100644 --- a/passbook/otp/models.py +++ b/passbook/otp/models.py @@ -15,6 +15,9 @@ class OTPFactor(Factor): type = 'passbook.otp.factors.OTPFactor' form = 'passbook.otp.forms.OTPFactorForm' + def has_user_settings(self): + return _('OTP'), 'pficon-locked', 'passbook_otp:otp-user-settings' + def __str__(self): return "OTP Factor %s" % self.slug