Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. @login_required
  2. def logout_student(request):
  3. logout(request)
  4. # Redirect to a success page.
  5. return HttpResponseRedirect('/index/')
  6.  
  7. def logout(request):
  8. """
  9. Removes the authenticated user's ID from the request and flushes their
  10. session data.
  11. """
  12. # Dispatch the signal before the user is logged out so the receivers have a
  13. # chance to find out *who* logged out.
  14. user = getattr(request, 'user', None)
  15. if hasattr(user, 'is_authenticated') and not user.is_authenticated():
  16. user = None
  17. user_logged_out.send(sender=user.__class__, request=request, user=user)
  18.  
  19. request.session.flush()
  20. if hasattr(request, 'user'):
  21. from django.contrib.auth.models import AnonymousUser
  22. request.user = AnonymousUser()
  23.  
  24. def delete(self, session_key=None):
  25. if session_key is None:
  26. if self.session_key is None:
  27. return
  28. session_key = self.session_key
  29. try:
  30. Session.objects.get(session_key=session_key).delete()
  31. except Session.DoesNotExist:
  32. pass
Add Comment
Please, Sign In to add comment