feat: reset password working
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import SetPasswordMixin, BaseUserCreationForm
|
||||
from django.contrib.auth.forms import BaseUserCreationForm, SetPasswordMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.forms import EmailField
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import PasswordResetForm as BasePasswordResetForm
|
||||
from django.contrib.auth.forms import SetPasswordForm as BaseSetPasswordForm
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class PasswordResetForm(BasePasswordResetForm):
|
||||
pass
|
||||
|
||||
|
||||
def validate_token(token):
|
||||
is_valid = default_token_generator.check_token(token)
|
||||
|
||||
if not is_valid:
|
||||
raise ValidationError(_("El token no es válido o ha expirado"))
|
||||
|
||||
|
||||
class SetPasswordForm(BaseSetPasswordForm):
|
||||
token = forms.CharField(
|
||||
required=True,
|
||||
widget=forms.HiddenInput(),
|
||||
validators=[],
|
||||
)
|
||||
|
||||
def validate_token(self):
|
||||
is_valid = default_token_generator.check_token(self.user, self.data.get('token'))
|
||||
|
||||
if not is_valid:
|
||||
raise ValidationError(_("El token no es válido o ha expirado"))
|
||||
|
||||
def is_valid(self):
|
||||
try:
|
||||
self.validate_token()
|
||||
except ValidationError as e:
|
||||
self.add_error(self.token, str(e))
|
||||
return False
|
||||
return super().is_valid()
|
||||
|
||||
Reference in New Issue
Block a user