-
Notifications
You must be signed in to change notification settings - Fork 0
Force all users to logout
Chandra Y edited this page Jun 26, 2024
·
1 revision
- Connect to portal_django (core_portal_django, if you are on local dev)
docker exec -it portal_django /bin/bash
- attach to shell
python3 manage.py shell
- run
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
from django.utils import timezone
sessions = Session.objects.filter(expire_date__gte=timezone.now())
for session in sessions:
data = session.get_decoded()
user_id = data.get('_auth_user_id')
if user_id:
try:
user = User.objects.get(pk=user_id)
print(f"Expiry Date: {session.expire_date}, Username: {user.username}")
print(' Deleting session object')
session.delete()
except User.DoesNotExist:
print(f"Username: Unknown (user_id: {user_id})")
else:
print(f"Expiry Date: {session.expire_date}, can't find user")
TACC ACI WMA Core-Portal Project Documentation