Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #229 (ImproperlyConfigured error raised in auth_signals.p… #231

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions easyaudit/signals/auth_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

from easyaudit.middleware.easyaudit import get_current_request
from easyaudit.models import LoginEvent
from easyaudit.settings import REMOTE_ADDR_HEADER, WATCH_AUTH_EVENTS, LOGGING_BACKEND
from easyaudit.settings import REMOTE_ADDR_HEADER, WATCH_AUTH_EVENTS, LOGGING_BACKEND, \
DATABASE_ALIAS

audit_logger = import_string(LOGGING_BACKEND)()


def user_logged_in(sender, request, user, **kwargs):
try:
with transaction.atomic():
with transaction.atomic(using=DATABASE_ALIAS):
login_event = audit_logger.login({
'login_type': LoginEvent.LOGIN,
'username': getattr(user, user.USERNAME_FIELD),
Expand All @@ -24,7 +25,7 @@ def user_logged_in(sender, request, user, **kwargs):

def user_logged_out(sender, request, user, **kwargs):
try:
with transaction.atomic():
with transaction.atomic(using=DATABASE_ALIAS):
login_event = audit_logger.login({
'login_type': LoginEvent.LOGOUT,
'username': getattr(user, user.USERNAME_FIELD),
Expand All @@ -37,7 +38,7 @@ def user_logged_out(sender, request, user, **kwargs):

def user_login_failed(sender, credentials, **kwargs):
try:
with transaction.atomic():
with transaction.atomic(using=DATABASE_ALIAS):
request = get_current_request() # request argument not available in django < 1.11
user_model = get_user_model()
login_event = audit_logger.login({
Expand Down