File: forms.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (28 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Forms for the Single Sign On app of FreedomBox.
"""

from captcha.fields import CaptchaField
from django import forms
from django.contrib.auth.forms import \
    AuthenticationForm as DjangoAuthenticationForm
from django.utils.translation import gettext_lazy as _


class AuthenticationForm(DjangoAuthenticationForm):
    """Authentication form with an additional username field attributes."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['username'].widget.attrs.update({
            'autofocus': 'autofocus',
            'autocapitalize': 'none',
            'autocomplete': 'username'
        })


class CaptchaForm(forms.Form):
    """Form with a CAPTCHA field to use after 3 invalid login attempts."""
    captcha = CaptchaField(
        label=_('Enter the letters in the image to proceed to the login page'))