This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/factors/password/forms.py

57 lines
1.9 KiB
Python
Raw Normal View History

2019-02-16 08:52:37 +00:00
"""passbook administration forms"""
from django import forms
from django.conf import settings
from django.contrib.admin.widgets import FilteredSelectMultiple
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
from passbook.flows.forms import GENERAL_FIELDS
from passbook.lib.utils.reflection import path_to_class
2019-02-16 08:52:37 +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-10-07 14:33:48 +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",
}
)
)
class PasswordFactorForm(forms.ModelForm):
"""Form to create/edit Password Factors"""
2019-02-16 08:52:37 +00:00
class Meta:
model = PasswordFactor
2019-12-31 11:51:16 +00:00
fields = GENERAL_FIELDS + ["backends", "password_policies", "reset_factors"]
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),
}
help_texts = {
"policies": _(
"Policies which determine if this factor applies to the current user."
)
}