Skip to content

Commit

Permalink
Use clear_session to logout current user
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Mar 1, 2024
1 parent 1bca3ac commit 8b9a98c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 2 additions & 5 deletions python/nav/web/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from nav.models.profiles import Account, AccountGroup
from nav.web.auth import ldap, remote_user
from nav.web.auth.sudo import desudo
from nav.web.auth.utils import ACCOUNT_ID_VAR
from nav.web.auth.utils import clear_session


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -151,10 +151,7 @@ def logout(request, sudo=False):
return reverse('webfront-index')
else:
account = request.account
del request.session[ACCOUNT_ID_VAR]
del request.account
request.session.set_expiry(datetime.now())
request.session.save()
clear_session(request)
_logger.debug('logout: logout %s', account.login)
LogEntry.add_log_entry(account, 'log-out', '{actor} logged out', before=account)
_logger.debug('logout: redirect to "/" after logout')
Expand Down
5 changes: 2 additions & 3 deletions python/nav/web/auth/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from nav.auditlog.models import LogEntry
from nav.django.utils import is_admin, get_account
from nav.models.profiles import Account
from nav.web.auth.utils import set_account, ACCOUNT_ID_VAR
from nav.web.auth.utils import set_account, ACCOUNT_ID_VAR, clear_session


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,8 +68,7 @@ def desudo(request):
original_user_id = request.session[SUDOER_ID_VAR]
original_user = Account.objects.get(id=original_user_id)

del request.session[ACCOUNT_ID_VAR]
del request.session[SUDOER_ID_VAR]
clear_session(request)
set_account(request, original_user)
_logger.info(
'DeSudo: "%s" no longer acting as "%s"', original_user, request.account
Expand Down

0 comments on commit 8b9a98c

Please sign in to comment.