@receiver(user_logged_in)
@receiver(user_logged_out)
def enforce_single_login(sender, request, user, signal, **kwargs):
 if settings.FEATURES.get('PREVENT_CONCURRENT_LOGINS', False):
  if (signal == user_logged_in):
   key = request.session.session_key
  else:
   key = None
  if user:
   (user_profile, __) = UserProfile.objects.get_or_create(user=user, defaults={'name': user.username})
   if user_profile:
    user.profile.set_login_session(key)

@ receiver ( user_logged_in ) @ receiver ( user_logged_out ) def enforce_single_login ( sender , request , user , signal , ** kwargs ) : if settings . FEATURES . get ( 'PREVENT_CONCURRENT_LOGINS' , False ) : if ( signal == user_logged_in ) : key = request . session . session_key else : key = None if user : ( user_profile , __ ) = UserProfile . objects . get_or_create ( user = user , defaults = { 'name' : user . username } ) if user_profile : user . profile . set_login_session ( key )
sets the current session id in the user profile .