Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
  • Loading branch information
rissson committed May 15, 2024
1 parent 1a9bc4e commit b8149c2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
4 changes: 2 additions & 2 deletions authentik/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ def from_request(request: HttpRequest, user: User) -> Optional["AuthenticatedSes

if not hasattr(request, "session") or not request.session.session_key:
return None
AuthenticatedSession.objects.filter(session_key=session_key).update(
AuthenticatedSession.objects.filter(session_key=request.session.session_key).update(
user=user,
last_ip=ClientIPMiddleware.get_client_ip(request),
last_user_agent=request.META.get("HTTP_USER_AGENT", ""),
)
return AuthenticatedSession.objects.filter(session_key=session_key).first()
return AuthenticatedSession.objects.filter(session_key=request.session.session_key).first()
12 changes: 3 additions & 9 deletions authentik/core/sessions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import logging

from asgiref.sync import sync_to_async
from django.contrib.session.backends.db import SessionStore as BaseSessionStore
from django.contrib.sessions.backends.base import CreateError, SessionBase, UpdateError
from django.contrib.sessions.backends.db import SessionStore as BaseSessionStore
from django.core.exceptions import SuspiciousOperation
from django.db import DatabaseError, IntegrityError, router, transaction
from django.utils import timezone
from django.utils.functional import cached_property
from structlog import get_logger

LOGGER = get_logger()
Expand All @@ -24,15 +18,15 @@ def _get_session_from_db(self):
return self.model.objects.get(session_key=self.session_key, expires__gt=timezone.now())
except (self.model.DoesNotExist, SuspiciousOperation) as exc:
if isinstance(exc, SuspiciousOperation):
LOGGER.warning(str(e))
LOGGER.warning(str(exc))
self._session_key = None

async def _aget_session_from_db(self):
try:
return self.model.objects.aget(session_key=self.session_key, expires__gt=timezone.now())
except (self.model.DoesNotExist, SuspiciousOperation) as exc:
if isinstance(exc, SuspiciousOperation):
LOGGER.warning(str(e))
LOGGER.warning(str(exc))
self._session_key = None

def create_model_instance(self, data):
Expand Down
6 changes: 0 additions & 6 deletions authentik/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

from datetime import datetime, timedelta

from django.conf import ImproperlyConfigured
from django.contrib.sessions.backends.cache import KEY_PREFIX
from django.contrib.sessions.backends.db import SessionStore as DBSessionStore
from django.core.cache import cache
from django.utils.timezone import now
from structlog.stdlib import get_logger

from authentik.core.models import (
USER_ATTRIBUTE_EXPIRES,
USER_ATTRIBUTE_GENERATED,
AuthenticatedSession,
ExpiringModel,
User,
)
from authentik.events.system_tasks import SystemTask, TaskStatus, prefill_task
from authentik.lib.config import CONFIG
from authentik.root.celery import CELERY_APP

LOGGER = get_logger()
Expand Down
1 change: 0 additions & 1 deletion authentik/root/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path

from celery.schedules import crontab
from django.conf import ImproperlyConfigured
from sentry_sdk import set_tag

from authentik import ENV_GIT_HASH_KEY, __version__
Expand Down

0 comments on commit b8149c2

Please sign in to comment.