2019-02-16 08:52:37 +00:00
|
|
|
"""passbook administration forms"""
|
|
|
|
from django import forms
|
2019-03-10 20:47:08 +00:00
|
|
|
from django.conf import settings
|
2019-03-10 17:34:09 +00:00
|
|
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
|
|
|
from django.utils.translation import gettext as _
|
2019-02-16 08:52:37 +00:00
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
from passbook.factors.forms import GENERAL_FIELDS
|
|
|
|
from passbook.factors.password.models import PasswordFactor
|
2019-03-10 20:47:08 +00:00
|
|
|
from passbook.lib.utils.reflection import path_to_class
|
2019-02-16 08:52:37 +00:00
|
|
|
|
|
|
|
|
2019-03-10 20:47:08 +00:00
|
|
|
def get_authentication_backends():
|
|
|
|
"""Return all available authentication backends as tuple set"""
|
|
|
|
for backend in settings.AUTHENTICATION_BACKENDS:
|
|
|
|
klass = path_to_class(backend)
|
|
|
|
yield backend, getattr(klass(), 'name', '%s (%s)' % (klass.__name__, klass.__module__))
|
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
|
2019-02-24 21:39:09 +00:00
|
|
|
class PasswordFactorForm(forms.ModelForm):
|
|
|
|
"""Form to create/edit Password Factors"""
|
2019-02-16 08:52:37 +00:00
|
|
|
|
2019-02-24 21:39:09 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = PasswordFactor
|
2019-02-25 14:41:36 +00:00
|
|
|
fields = GENERAL_FIELDS + ['backends', 'password_policies']
|
2019-02-24 21:39:09 +00:00
|
|
|
widgets = {
|
|
|
|
'name': forms.TextInput(),
|
|
|
|
'order': forms.NumberInput(),
|
2019-03-10 20:47:08 +00:00
|
|
|
'policies': FilteredSelectMultiple(_('policies'), False),
|
|
|
|
'backends': FilteredSelectMultiple(_('backends'), False,
|
2019-04-29 21:16:04 +00:00
|
|
|
choices=get_authentication_backends()),
|
|
|
|
'password_policies': FilteredSelectMultiple(_('password policies'), False),
|
2019-03-08 14:11:01 +00:00
|
|
|
}
|