Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.forms import SetPasswordForm
- class UserSetPasswordForm(SetPasswordForm):
- password = forms.CharField(label=_("Contraseña"), widget=forms.PasswordInput)
- confirm_password = forms.CharField(label=_("Confirmar contraseña"), widget=forms.PasswordInput)
- def __init__(self, *args, **kwargs):
- super(UserSetPasswordForm, self).__init__(*args, **kwargs)
- self.fields['password'].widget.attrs.update({'class': 'form-control form-control-lg bg-gray-800 border-dark'})
- self.fields['confirm_password'].widget.attrs.update({'class': 'form-control form-control-lg bg-gray-800 border-dark'})
- # add fields to the form
- self.fields['password'].label = "Contraseña"
- self.fields['confirm_password'].label = "Confirmar contraseña"
- def clean(self):
- cleaned_data = super().clean()
- password = cleaned_data.get("password")
- confirm_password = cleaned_data.get("confirm_password")
- if password != confirm_password:
- raise forms.ValidationError("Las contraseñas no coinciden")
- return cleaned_data
- def save(self, commit=True):
- user = super().save(commit=False)
- user.set_password(self.cleaned_data["password"])
- if commit:
- user.save()
- return user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement