Пример #1
0
    def clean(self):
        username = self.cleaned_data.get("username")
        password = self.cleaned_data.get("password")

        if username and password:
            if not check_rate_limit("login", self.request):
                raise forms.ValidationError(
                    _("Too many authentication attempts from this location."))
            self.user_cache = authenticate(self.request,
                                           username=username,
                                           password=password)
            if self.user_cache is None:
                for user in try_get_user(username, True):
                    audit = AuditLog.objects.create(
                        user,
                        self.request,
                        "failed-auth",
                        method="password",
                        name=username,
                    )
                    audit.check_rate_limit(self.request)
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages["invalid_login"], code="invalid_login")
            if not self.user_cache.is_active:
                raise forms.ValidationError(self.error_messages["inactive"],
                                            code="inactive")
            AuditLog.objects.create(self.user_cache,
                                    self.request,
                                    "login",
                                    method="password",
                                    name=username)
            adjust_session_expiry(self.request)
            reset_rate_limit("login", self.request)
        return self.cleaned_data
Пример #2
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            if not check_rate_limit('login', self.request):
                raise forms.ValidationError(
                    _('Too many authentication attempts from this location!')
                )
            self.user_cache = authenticate(
                self.request, username=username, password=password
            )
            if self.user_cache is None:
                for user in try_get_user(username, True):
                    audit = AuditLog.objects.create(
                        user,
                        self.request,
                        'failed-auth',
                        method='Password',
                        name=username,
                    )
                    audit.check_rate_limit(self.request)
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages['invalid_login'], code='invalid_login'
                )
            if not self.user_cache.is_active:
                raise forms.ValidationError(
                    self.error_messages['inactive'], code='inactive'
                )
            AuditLog.objects.create(
                self.user_cache, self.request, 'login', method='Password', name=username
            )
            reset_rate_limit('login', self.request)
        return self.cleaned_data
Пример #3
0
    def clean(self):
        username = self.cleaned_data.get("username")
        password = self.cleaned_data.get("password")

        if username and password:
            if not check_rate_limit("login", self.request):
                lockout_period = get_rate_setting("login", "LOCKOUT") // 60
                raise forms.ValidationError(
                    ngettext(
                        (
                            "Too many authentication attempts from this location. "
                            "Please try again in %d minute."
                        ),
                        (
                            "Too many authentication attempts from this location. "
                            "Please try again in %d minutes."
                        ),
                        lockout_period,
                    )
                    % lockout_period
                )
            self.user_cache = authenticate(
                self.request, username=username, password=password
            )
            if self.user_cache is None:
                for user in try_get_user(username, True):
                    audit = AuditLog.objects.create(
                        user,
                        self.request,
                        "failed-auth",
                        method="password",
                        name=username,
                    )
                    audit.check_rate_limit(self.request)
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages["invalid_login"], code="invalid_login"
                )
            if not self.user_cache.is_active or self.user_cache.is_bot:
                raise forms.ValidationError(
                    self.error_messages["inactive"], code="inactive"
                )
            AuditLog.objects.create(
                self.user_cache, self.request, "login", method="password", name=username
            )
            adjust_session_expiry(self.request)
            reset_rate_limit("login", self.request)
        return self.cleaned_data
Пример #4
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            if not check_rate_limit(self.request):
                raise forms.ValidationError(
                    _('Too many authentication attempts!')
                )
            self.user_cache = authenticate(
                username=username,
                password=password
            )
            if self.user_cache is None:
                try:
                    notify_account_activity(
                        try_get_user(username),
                        self.request,
                        'failed-auth',
                        method='Password',
                        name=username,
                    )
                except User.DoesNotExist:
                    pass
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                )
            elif not self.user_cache.is_active:
                raise forms.ValidationError(
                    self.error_messages['inactive'],
                    code='inactive',
                )
            else:
                notify_account_activity(
                    self.user_cache,
                    self.request,
                    'login',
                    method='Password',
                    name=username,
                )
            reset_rate_limit(self.request)
        return self.cleaned_data
Пример #5
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            if not check_rate_limit(self.request):
                raise forms.ValidationError(
                    _('Too many authentication attempts!')
                )
            self.user_cache = authenticate(
                username=username,
                password=password
            )
            if self.user_cache is None:
                try:
                    notify_account_activity(
                        try_get_user(username),
                        self.request,
                        'failed-auth',
                        method='Password',
                        name=username,
                    )
                except User.DoesNotExist:
                    pass
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                )
            elif not self.user_cache.is_active:
                raise forms.ValidationError(
                    self.error_messages['inactive'],
                    code='inactive',
                )
            else:
                notify_account_activity(
                    self.user_cache,
                    self.request,
                    'login',
                    method='Password',
                    name=username,
                )
            reset_rate_limit(self.request)
        return self.cleaned_data
Пример #6
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            if not check_rate_limit('login', self.request):
                raise forms.ValidationError(
                    _('Too many authentication attempts from this location!')
                )
            self.user_cache = authenticate(
                self.request,
                username=username,
                password=password
            )
            if self.user_cache is None:
                for user in try_get_user(username, True):
                    notify_account_activity(
                        user,
                        self.request,
                        'failed-auth',
                        method=ugettext('Password'),
                        name=username,
                    )
                rotate_token(self.request)
                raise forms.ValidationError(
                    self.error_messages['invalid_login'],
                    code='invalid_login',
                )
            elif not self.user_cache.is_active:
                raise forms.ValidationError(
                    self.error_messages['inactive'],
                    code='inactive',
                )
            else:
                notify_account_activity(
                    self.user_cache,
                    self.request,
                    'login',
                    method=ugettext('Password'),
                    name=username,
                )
            reset_rate_limit('login', self.request)
        return self.cleaned_data