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


Python AccessAudit.view方法代碼示例

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


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

示例1: testRepeatedFailedLogin

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
    def testRepeatedFailedLogin(self):
        from auditcare.decorators import login
        login.FAILURE_LIMIT = 3
        login.LOCK_OUT_AT_FAILURE=True
        login.COOLOFF_TIME = timedelta(seconds=4)

        start_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        response = self.client.post(reverse('auth_login'), {'username': '[email protected]', 'password': 'wrongwrongwrong'})

        firstlogin_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        self.assertEquals(start_count+1, firstlogin_count)


        first_audit = get_latest_access(['user', '[email protected]'])
        self.assertEquals(first_audit.access_type, models.ACCESS_FAILED)
        self.assertEquals(first_audit.failures_since_start, 1)
        start_failures = first_audit.failures_since_start

        for n in range(1,3):
            #we are logging in within the cooloff period, so let's check to see if it doesn't increment.
            response = self.client.post(reverse('auth_login'), {'username': '[email protected]', 'password': 'wrongwrongwrong'})
            next_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
            self.assertEquals(firstlogin_count, next_count)

            next_audit = get_latest_access(['user', '[email protected]'])
            self.assertEquals(next_audit.access_type, models.ACCESS_FAILED)
            self.assertEquals(next_audit.failures_since_start, n+start_failures)
            time.sleep(1)
        time.sleep(3)
        response = self.client.post(reverse('auth_login'), {'username': '[email protected]', 'password': 'wrongwrong'})
        cooled_audit = get_latest_access(['user', '[email protected]'])
        self.assertEquals(cooled_audit.failures_since_start,1)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:34,代碼來源:auth.py

示例2: testLogin

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
    def testLogin(self):

        #login
        start_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        response = self.client.post(reverse('auth_login'), {'username': '[email protected]', 'password': 'mockmock'})
        login_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        self.assertEqual(start_count+1, login_count)

        latest_audit = get_latest_access(['user', '[email protected]'])
        self.assertEquals(latest_audit.access_type, models.ACCESS_LOGIN)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:12,代碼來源:auth.py

示例3: testSingleFailedLogin

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
    def testSingleFailedLogin(self):
        start_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        response = self.client.post(reverse('auth_login'), {'username': '[email protected]', 'password': 'wrongwrongwrong'})

        login_count = AccessAudit.view('auditcare/login_events', key=['user', '[email protected]']).count()
        self.assertEquals(start_count+1, login_count)
        #got the basic count, now let's inspect this value to see what kind of result it is.

        latest_audit = get_latest_access(['user', '[email protected]'])
        self.assertEquals(latest_audit.access_type, models.ACCESS_FAILED)
        self.assertEquals(latest_audit.failures_since_start, 1)
開發者ID:dimagi,項目名稱:auditcare,代碼行數:13,代碼來源:auth.py

示例4: auditor

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
def auditor(request, template="ewsghana/auditor.html"):
    auditEvents = AccessAudit.view("auditcare/by_date_access_events", descending=True, include_docs=True).all()
    realEvents = []
    for a in auditEvents:
        designation = organization = facility = location = first_name = last_name = ''
        try:
            user = User.objects.get(username=a.user)
        except User.DoesNotExist:
            # OK - anonymous user
            pass
        else:
            first_name = user.first_name
            last_name = user.last_name
            try:
                profile = user.get_profile()
            except LogisticsProfile.DoesNotExist:
                profile = None
            else:
                designation = profile.designation if profile.designation else '' 
                organization = profile.organization if profile.organization else ''
                facility = profile.supply_point if profile.supply_point else ''
                location = profile.location if profile.location else ''
        realEvents.append({'user': a.user, 
                           'date': a.event_date, 
                           'class': a.doc_type, 
                           'access_type': a.access_type, 
                           'first_name': first_name,
                           'last_name': last_name,
                           'designation': designation, 
                           'organization': organization, 
                           'facility': facility, 
                           'location': location })
    return render_to_response(template, 
                              {"audit_table": AuditLogTable(realEvents, request=request)}, 
                              context_instance=RequestContext(request))
開發者ID:andile2012,項目名稱:logistics,代碼行數:37,代碼來源:views.py

示例5: export_all

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
def export_all(request):
    auditEvents = AccessAudit.view("auditcare/by_date_access_events", descending=True, include_docs=True).all()
    response = HttpResponse()
    response['Content-Disposition'] = 'attachment; filename="AuditAll.xls"'
    writer = csv.UnicodeWriter(response)
    writer.writerow(['User', 'Access Type', 'Date'])
    for a in auditEvents:
        writer.writerow([a.user, a.access_type, a.event_date])
    return response
開發者ID:dimagi,項目名稱:auditcare,代碼行數:11,代碼來源:views.py

示例6: auditAll

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
def auditAll(request, template="auditcare/index.html"):
    auditEvents = AccessAudit.view("auditcare/by_date_access_events", descending=True, include_docs=True).all()
    realEvents = [{'user': a.user, 
                   'date': a.event_date, 
                   'class': a.doc_type, 
                   'access_type': a.access_type } for a in auditEvents]
    return render_to_response(template, 
                              {"audit_table": AuditLogTable(realEvents, request=request)}, 
                              context_instance=RequestContext(request))
開發者ID:dimagi,項目名稱:auditcare,代碼行數:11,代碼來源:views.py

示例7: get_user_attempt

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
def get_user_attempt(request):
    """
    Returns access attempt record if it exists.
    Otherwise return None.
    """
    ip = request.META.get('REMOTE_ADDR', '')
    if USE_USER_AGENT:
        ua = request.META.get('HTTP_USER_AGENT', '<unknown>')

        attempts = AccessAudit.view('auditcare/login_events', key=['ip_ua',ip, ua], include_docs=True, limit=25).all()

        #attempts = AccessAttempt.objects.filter( user_agent=ua, ip_address=ip )
    else:
        attempts = AccessAudit.view('auditcare/login_events',key=['ip', ip], include_docs=True, limit=25).all()
        #attempts = AccessAttempt.objects.filter( ip_address=ip )

    attempts = sorted(attempts, key=lambda x: x.event_date, reverse=True)
    if not attempts:
        log.info("No attempts for given access, creating new attempt")
        return None

    #walk the attempts
    attempt = None
    for at in attempts:
        if at.access_type == models.ACCESS_FAILED:
            attempt = at
            break
        elif at.access_type == models.ACCESS_LOGIN:
            attempt = None
            break
        elif at.access_type == models.ACCESS_LOGOUT:
            attempt = None
            break



    if COOLOFF_TIME and attempt and datetime.utcnow() - attempt.event_date < COOLOFF_TIME:
        log.info("Last login failure is still within the cooloff time, incrementing last access attempt.")
    else:
        log.info("Last login failure is outside the cooloff time, creating new access attempt.")
        return None
    return attempt
開發者ID:,項目名稱:,代碼行數:44,代碼來源:

示例8: get_latest_access

# 需要導入模塊: from auditcare.models import AccessAudit [as 別名]
# 或者: from auditcare.models.AccessAudit import view [as 別名]
def get_latest_access(key):
    access_events = AccessAudit.view('auditcare/login_events', key=key, include_docs=True).all()
    access_events = sorted(access_events, key=lambda x: x.event_date, reverse=True)
    return access_events[0]
開發者ID:dimagi,項目名稱:auditcare,代碼行數:6,代碼來源:testutils.py


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