registration fixes

This commit is contained in:
Alicja Cięciwa
2020-11-15 13:32:50 +01:00
parent 0525450a90
commit 3ffce6c7c3
15 changed files with 117 additions and 63 deletions

View File

@@ -85,19 +85,19 @@ class UserCreationForm(forms.ModelForm):
password.
"""
error_messages = {
'password_mismatch': _('The two password fields didnt match.'),
'password_mismatch': _('Hasła się nie zgadzają'),
}
password1 = forms.CharField(
label=_("Password"),
label="",
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
help_text=password_validation.password_validators_help_text_html(),
help_text=None,
)
password2 = forms.CharField(
label=_("Password confirmation"),
label="",
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
strip=False,
help_text=_("Enter the same password as before, for verification."),
help_text=None,
)
class Meta:
@@ -109,6 +109,32 @@ class UserCreationForm(forms.ModelForm):
super().__init__(*args, **kwargs)
if self._meta.model.USERNAME_FIELD in self.fields:
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs['autofocus'] = True
self.fields['username'].help_text = None
self.fields['username'] = forms.CharField(
widget=forms.TextInput(attrs={
'placeholder': 'Nazwa użytkownika'
}),
error_messages={
'required': 'Wpisz nazwę użytkownika',
})
self.fields['password1'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
self.fields['password2'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Powtórz hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
for field in ['username', 'password1', 'password2']:
self.fields[field].help_text = None
self.fields[field].label = ''
def clean_password2(self):
password1 = self.cleaned_data.get("password1")

View File

@@ -99,8 +99,8 @@ class MinimumLengthValidator:
if len(password) < self.min_length:
raise ValidationError(
ngettext(
"This password is too short. It must contain at least %(min_length)d character.",
"This password is too short. It must contain at least %(min_length)d characters.",
"Hasło jest zbyt krótkie - musi zawierać przynajmniej %(min_length)d znaków.",
"Hasło jest zbyt krótkie - musi zawierać przynajmniej %(min_length)d znaków.",
self.min_length
),
code='password_too_short',
@@ -109,8 +109,8 @@ class MinimumLengthValidator:
def get_help_text(self):
return ngettext(
"Your password must contain at least %(min_length)d character.",
"Your password must contain at least %(min_length)d characters.",
"Hasło musi zawierać przynajmniej %(min_length)d znaków.",
"Hasło musi zawierać przynajmniej %(min_length)d znaków.",
self.min_length
) % {'min_length': self.min_length}
@@ -148,7 +148,7 @@ class UserAttributeSimilarityValidator:
except FieldDoesNotExist:
verbose_name = attribute_name
raise ValidationError(
_("The password is too similar to the %(verbose_name)s."),
_("Hasło jest zbyt podobne do %(verbose_name)s."),
code='password_too_similar',
params={'verbose_name': verbose_name},
)
@@ -180,7 +180,7 @@ class CommonPasswordValidator:
def validate(self, password, user=None):
if password.lower().strip() in self.passwords:
raise ValidationError(
_("This password is too common."),
_("To hasło jest zbyt powszechne."),
code='password_too_common',
)