diff --git a/README.md b/README.md index 38a3e6b..3ce20c2 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,14 @@ You will run `migrate` to create/migrate the useraudit DB tables. Ex: ``` $ ./manage.py migrate useraudit ``` +Then add useraudit to your project url for the activate link to work in django admin. + +``` +... +url(r'^useraudit/', include('useraudit.urls')), +... +``` + ### Model changes for password expiration diff --git a/useraudit/backend.py b/useraudit/backend.py index aee1140..99abe3d 100644 --- a/useraudit/backend.py +++ b/useraudit/backend.py @@ -24,7 +24,7 @@ def user_pre_save(sender, instance=None, raw=False, **kwargs): # that the user isn't inactivated on next login by the AuthFailedLoggerBackend current_user = sender.objects.get(pk=user.pk) if not current_user.is_active and user.is_active: - LoginAttemptLogger().reset(user.username) + LoginAttemptLogger().reset(user.get_username()) class AuthFailedLoggerBackend(object): diff --git a/useraudit/middleware.py b/useraudit/middleware.py index 6e1c001..30466ae 100644 --- a/useraudit/middleware.py +++ b/useraudit/middleware.py @@ -1,4 +1,10 @@ import threading +try: + from django.utils.deprecation import MiddlewareMixin +except ImportError: + class MiddlewareMixin(object): + def __init__(self, *args, **kwargs): + pass thread_data = threading.local() @@ -6,8 +12,7 @@ def get_request(): return getattr(thread_data, 'request', None) - -class RequestToThreadLocalMiddleware(object): +class RequestToThreadLocalMiddleware(MiddlewareMixin): def process_request(self, request): thread_data.request = request diff --git a/useraudit/models.py b/useraudit/models.py index 79f8cdb..45a5159 100644 --- a/useraudit/models.py +++ b/useraudit/models.py @@ -2,6 +2,7 @@ import datetime import logging from django.db import models +from django.utils import timezone from django.contrib.auth.signals import user_logged_in from .signals import password_has_expired, account_has_expired, login_failure_limit_reached @@ -20,14 +21,14 @@ class LoginAttemptLogger(object): def reset(self, username): defaults = { 'count': 0, - 'timestamp': datetime.datetime.now() + 'timestamp': timezone.now() } LoginAttempt.objects.update_or_create(username=username, defaults=defaults) def increment(self, username): obj, created = LoginAttempt.objects.get_or_create(username=username) obj.count += 1 - obj.timestamp = datetime.datetime.now() + obj.timestamp = timezone.now() obj.save()