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
|
2020-02-27 15:39:30 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-02-16 08:52:37 +00:00
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
from passbook.factors.password.models import PasswordFactor
|
2020-05-07 19:30:52 +00:00
|
|
|
from passbook.flows.forms import GENERAL_FIELDS
|
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)
|
2019-12-31 11:51:16 +00:00
|
|
|
yield backend, getattr(
|
|
|
|
klass(), "name", "%s (%s)" % (klass.__name__, klass.__module__)
|
|
|
|
)
|
2019-03-10 20:47:08 +00:00
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
|
2019-10-08 12:23:02 +00:00
|
|
|
class PasswordForm(forms.Form):
|
|
|
|
"""Password authentication form"""
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
password = forms.CharField(
|
|
|
|
widget=forms.PasswordInput(
|
|
|
|
attrs={
|
|
|
|
"placeholder": _("Password"),
|
|
|
|
"autofocus": "autofocus",
|
|
|
|
"autocomplete": "current-password",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2019-10-08 12:23:02 +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-12-31 11:51:16 +00:00
|
|
|
fields = GENERAL_FIELDS + ["backends", "password_policies", "reset_factors"]
|
2019-02-24 21:39:09 +00:00
|
|
|
widgets = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"name": forms.TextInput(),
|
|
|
|
"order": forms.NumberInput(),
|
|
|
|
"policies": FilteredSelectMultiple(_("policies"), False),
|
|
|
|
"backends": FilteredSelectMultiple(
|
|
|
|
_("backends"), False, choices=get_authentication_backends()
|
|
|
|
),
|
|
|
|
"password_policies": FilteredSelectMultiple(_("password policies"), False),
|
|
|
|
"reset_factors": FilteredSelectMultiple(_("reset factors"), False),
|
2019-03-08 14:11:01 +00:00
|
|
|
}
|
2020-02-27 15:39:30 +00:00
|
|
|
help_texts = {
|
|
|
|
"policies": _(
|
|
|
|
"Policies which determine if this factor applies to the current user."
|
|
|
|
)
|
|
|
|
}
|