def clean_email(self):
     email = self.cleaned_data.get('email')
     if email != self.request.user.email:
         raise forms.ValidationError(
             self.error_messages['invalid_email'],
             code='invalid_email',
         )
     return email
Exemple #2
0
 def clean_phone_number(self):
     """
     Validate phone number.
     """
     country_code = self.cleaned_data.get("country_code")
     if not country_code:
         raise forms.ValidationError("Enter a valid country code")
     phone_number = self.cleaned_data.get("phone_number")
     return TwilioValidation().phone_validation(country_code, phone_number)
    def get_invalid_login_error(self):
        """
        Raise invalid login error.

        Returns:
            error(object): Contains a message of what went wrong.
        """
        return forms.ValidationError(
            self.error_messages['invalid_login'],
            code='invalid_login',
        )
 def clean_email(self):
     """Validate email is correct."""
     email = self.cleaned_data.get('email')
     user = User.objects.filter(email=email).first()
     if not user:
         raise forms.ValidationError(
             self.error_messages['non_existent'],
             code='non_existent',
         )
     self.confirm_login_allowed(user)
     return email
 def clean_old_password(self):
     """
     Validate that the old_password field is correct.
     """
     old_password = self.cleaned_data["old_password"]
     if not self.user.check_password(old_password):
         raise forms.ValidationError(
             self.error_messages['password_incorrect'],
             code='password_incorrect',
         )
     return old_password
 def clean_password2(self):
     """
     Validate that both passwords entered by the user match.
     """
     password1 = self.cleaned_data.get("password1")
     password2 = self.cleaned_data.get("password2")
     if password1 and password2 and password1 != password2:
         raise forms.ValidationError(
             self.error_messages['password_mismatch'],
             code='password_mismatch',
         )
     return password2
 def confirm_login_allowed(self, user):
     """
     Controls whether the given User may log in. This is a policy setting,
     independent of end-user authentication. This default behavior is to
     allow login by active users, and reject login by inactive users.
     If the given user cannot log in, this method should raise a
     ``forms.ValidationError``.
     If the given user may log in, this method should return None.
     """
     if not user.is_active:
         self.redirect = True
         raise forms.ValidationError(
             self.error_messages['inactive'],
             code='inactive',
         )
    def clean_email(self):
        """
        Validate email is correct.

        Returns:
            email(str): Returns user email if valid

        Raises:
            ValidationError(object): Invalid email exception
        """
        email = self.cleaned_data.get("email")
        if self.initial["email"] == email:
            raise forms.ValidationError(
                self.error_messages['invalid_email'],
                code='invalid_email',
            )
        return email