decorator container logg_off

This commit is contained in:
makram89 2022-01-27 23:30:11 +01:00
parent 341339ca8b
commit 1ca8118142

View File

@ -2,7 +2,7 @@ from django.db.models.signals import post_save
from django.dispatch import receiver
from DockerManager import DockerManager
from models import Profile, Session
from django.contrib.auth.signals import user_logged_in
from django.contrib.auth.signals import user_logged_in, user_logged_out
@receiver(post_save, sender=Profile)
@ -34,3 +34,15 @@ def profile_start_up(sender, instance, request, **kwargs):
session.save()
@receiver(user_logged_out)
def profile_logged_out(sender, instance, request, **kwargs):
# Obtaining container_id
session = Session.objects.get(id=instance.user_id)
container_id = session.container_id
# Turn off and delete container
docker_manager = DockerManager()
docker_manager.turn_off_container(container_id)
# Delete session
session.delete()