當前位置: 首頁>>代碼示例>>Python>>正文


Python AccessAudit.event_date方法代碼示例

本文整理匯總了Python中auditcare.models.AccessAudit.event_date方法的典型用法代碼示例。如果您正苦於以下問題:Python AccessAudit.event_date方法的具體用法?Python AccessAudit.event_date怎麽用?Python AccessAudit.event_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在auditcare.models.AccessAudit的用法示例。


在下文中一共展示了AccessAudit.event_date方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: log_request

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import event_date [as 別名]
def log_request(request, login_unsuccessful):
    failures = 0
    attempt = get_user_attempt(request)

    if attempt:
        failures = attempt.failures_since_start

    # no matter what, we want to lock them out
    # if they're past the number of attempts allowed
    if failures > FAILURE_LIMIT and LOCK_OUT_AT_FAILURE:
        # We log them out in case they actually managed to enter
        # the correct password.
        logout(request)
        log.warning('AXES: locked out %s after repeated login attempts.', attempt.ip_address)
        return False

    if login_unsuccessful:
        #interpret the auth form to get the user in question
        if request.method == "POST":
            form = AuthenticationForm(data=request.POST)
            if form.is_valid():
                attempted_username = form.get_user().username
            else:
                attempted_username = form.data.get('username')
                attempted_password = form.data.get('password')

        # add a failed attempt for this user
        failures += 1

        # Create an AccessAttempt record if the login wasn't successful
        # has already attempted, update the info
        if attempt:
            #attempt.get_data.append(query2str(request.GET.items()))
            #attempt.post_data.append(query2str(request.POST.items()))
            attempt.access_type = models.ACCESS_FAILED
            attempt.user = attempted_username
            attempt.http_accept = request.META.get('HTTP_ACCEPT', '<unknown>')
            attempt.path_info = request.META.get('PATH_INFO', '<unknown>')
            attempt.failures_since_start = failures
            attempt.event_date = datetime.utcnow() #why do we do this?
            attempt.save()
            log.info('AXES: Repeated login failure by %s. Updating access '
                     'record. Count = %s', attempt.ip_address, failures)
        else:
            ip = request.META.get('REMOTE_ADDR', '')
            ua = request.META.get('HTTP_USER_AGENT', '<unknown>')
            attempt = AccessAudit()
            attempt.event_date = datetime.utcnow()
            attempt.doc_type=AccessAudit.__name__
            attempt.access_type = models.ACCESS_FAILED
            attempt.user_agent=ua
            attempt.user = attempted_username
            attempt.ip_address=ip
            #attempt.get_data = [query2str(request.GET.items())]
            #attempt.post_data= [query2str(request.POST.items())]
            attempt.http_accept=request.META.get('HTTP_ACCEPT', '<unknown>')
            attempt.path_info=request.META.get('PATH_INFO', '<unknown>')
            attempt.failures_since_start=failures
            attempt.save()
            log.info('AXES: New login failure by %s. Creating access record.', ip)
    else:
        #it's a successful login.

        #if we're django 1.3, this will have already been logged.
        if django.get_version() < '1.3':
            AccessAudit.audit_login(request, request.user)

    return True
開發者ID:,項目名稱:,代碼行數:70,代碼來源:


注:本文中的auditcare.models.AccessAudit.event_date方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。