Beispiel #1
0
    def clean(self, username_email=None, password=None):
        """Clean the form and try to get user
        Parameterize username_email and password to allow invoking from subclass
        """
        if not username_email:
            username_email = self.cleaned_data.get('username_email',
                                                   '').strip()
        if not password:
            password = self.cleaned_data.get('password')

        if username_email and password:
            self.user_cache = authenticate_user_by_username_email(
                username_email, password)
        else:
            self.user_cache = None

        if self.user_cache is None:
            if 'username_email' in self.fields:
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                    params={
                        'username_email': self.fields['username_email'].label,
                        'password': self.fields['password'].label,
                    },
                )
            else:
                raise forms.ValidationError(
                    self.error_messages['invalid_password'],
                    code='invalid_password',
                    params={
                        'password': self.fields['password'].label,
                    },
                )
        elif not self.user_cache.is_active:
            raise forms.ValidationError(
                self.error_messages['inactive'],
                code='inactive',
            )
        else:
            # all good, do nothing
            pass

        return self.cleaned_data
Beispiel #2
0
    def clean(self, username_email=None, password=None):
        """Clean the form and try to get user
        Parameterize username_email and password to allow invoking from subclass
        """
        if not username_email:
            username_email = self.cleaned_data.get('username_email', '').strip()
        if not password:
            password = self.cleaned_data.get('password')

        if username_email and password:
            self.user_cache = authenticate_user_by_username_email(username_email, password)
        else:
            self.user_cache = None

        if self.user_cache is None:
            if 'username_email' in self.fields:
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                    params={
                        'username_email': self.fields['username_email'].label,
                        'password': self.fields['password'].label,
                    },
                )
            else:
                raise forms.ValidationError(
                    self.error_messages['invalid_password'],
                    code='invalid_password',
                    params={
                        'password': self.fields['password'].label,
                    },
                )
        elif not self.user_cache.is_active:
            raise forms.ValidationError(
                self.error_messages['inactive'],
                code='inactive',
            )
        else:
            # all good, do nothing
            pass

        return self.cleaned_data
    def clean(self, username_email=None, password=None):
        """Clean the form and try to get user
        Parameterize username_email and password to allow invoking from subclass
        """
        if not username_email:
            username_email = self.cleaned_data.get('username_email')
        if not password:
            password = self.cleaned_data.get('password')

        if username_email and password:
            self.user_cache = authenticate_user_by_username_email(username_email, password)
        else:
            self.user_cache = None

        if self.user_cache is None:
            raise forms.ValidationError(self.error_messages['invalid_login'])
        elif not self.user_cache.is_active:
            raise forms.ValidationError(self.error_messages['inactive'])
        else:
            # all good, do nothing
            pass

        self.check_for_test_cookie()
        return self.cleaned_data