mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-16 02:22:20 +01:00
Marietje 4.1: Addition of Django REST framework, Swagger, Dark mode and updates to Django and Bootstrap
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm, UsernameField
|
||||
from django.contrib.auth import get_user_model, password_validation
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class AuthenticationForm(BaseAuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
if user.activation_token:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['inactive'],
|
||||
code='inactive',
|
||||
self.error_messages["inactive"],
|
||||
code="inactive",
|
||||
)
|
||||
super(AuthenticationForm, self).confirm_login_allowed(user)
|
||||
|
||||
|
||||
class RegistrationForm(forms.ModelForm):
|
||||
error_messages = {
|
||||
'password_mismatch': _("The two password fields didn't match."),
|
||||
"password_mismatch": _("The two password fields didn't match."),
|
||||
}
|
||||
password1 = forms.CharField(
|
||||
label=_("Password"),
|
||||
@ -32,13 +32,13 @@ class RegistrationForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ('email',)
|
||||
field_classes = {'email': UsernameField}
|
||||
fields = ("email",)
|
||||
field_classes = {"email": UsernameField}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RegistrationForm, self).__init__(*args, **kwargs)
|
||||
if self._meta.model.USERNAME_FIELD in self.fields:
|
||||
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({'autofocus': ''})
|
||||
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({"autofocus": ""})
|
||||
|
||||
def clean_password2(self):
|
||||
password1 = self.cleaned_data.get("password1")
|
||||
@ -47,20 +47,20 @@ class RegistrationForm(forms.ModelForm):
|
||||
if len(password1) < 6:
|
||||
raise forms.ValidationError(
|
||||
_("A password must be at least 6 characters."),
|
||||
code='password_length',
|
||||
code="password_length",
|
||||
)
|
||||
|
||||
if password1 and password2 and password1 != password2:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['password_mismatch'],
|
||||
code='password_mismatch',
|
||||
self.error_messages["password_mismatch"],
|
||||
code="password_mismatch",
|
||||
)
|
||||
self.instance.username = self.cleaned_data.get('username')
|
||||
password_validation.validate_password(self.cleaned_data.get('password2'), self.instance)
|
||||
self.instance.username = self.cleaned_data.get("username")
|
||||
password_validation.validate_password(self.cleaned_data.get("password2"), self.instance)
|
||||
return password2
|
||||
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data.get("email") + '@science.ru.nl'
|
||||
email = self.cleaned_data.get("email") + "@science.ru.nl"
|
||||
return email
|
||||
|
||||
def save(self, commit=True):
|
||||
@ -73,7 +73,7 @@ class RegistrationForm(forms.ModelForm):
|
||||
|
||||
class ResetPasswordForm(forms.Form):
|
||||
error_messages = {
|
||||
'password_mismatch': _("The two password fields didn't match."),
|
||||
"password_mismatch": _("The two password fields didn't match."),
|
||||
}
|
||||
password1 = forms.CharField(
|
||||
label=_("Password"),
|
||||
@ -96,8 +96,8 @@ class ResetPasswordForm(forms.Form):
|
||||
|
||||
if password1 and password2 and password1 != password2:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['password_mismatch'],
|
||||
code='password_mismatch',
|
||||
self.error_messages["password_mismatch"],
|
||||
code="password_mismatch",
|
||||
)
|
||||
password_validation.validate_password(self.cleaned_data.get('password2'))
|
||||
password_validation.validate_password(self.cleaned_data.get("password2"))
|
||||
return password2
|
||||
|
||||
Reference in New Issue
Block a user