Exemple #1
0
    def clean_email(self):
        """
        Validates that an active user exists with the given email address.
        """
        email = self.cleaned_data["email"]
        self.users_cache = User.objects(email__iexact=email, is_active=True)

        if not len(self.users_cache):
            raise forms.ValidationError(self.error_messages['unknown'])            
        if not any(user.is_active for user in self.users_cache):
            # none of the filtered users are active
            raise forms.ValidationError(self.error_messages['unknown'])
        if any((user.password == UNUSABLE_PASSWORD)
               for user in self.users_cache):
            raise forms.ValidationError(self.error_messages['unusable'])
            
        return email
Exemple #2
0
 def authenticate(self, username=None, password=None):
     user = Bee.objects(username=username.lower()).first()
     if user:
         if password and user.check_password(password):
             return user
     return None