Disconnect another django user

0

Good Morning I made a control of user sessions through login and logout: In login before logging it does an insert in my table:

cursor.execute("INSERT INTO usuarios_sessoes (usuario, datahorainicio) VALUES ('%s', '%s')" % (str(username),timezone.now().strftime('%d/%m/%Y %H:%M:%S')))

and logout does update:

  cursor.execute("""select id
                  from usuarios_sessoes
                  where usuario='"""+str(request.user)+"""'
                  order by datahorainicio desc limit 1""")
    id = cursor.fetchone()[0]  

With this I have my session control, but what I need is that a superuser, can move any user, I did not find a solution for that.

    
asked by anonymous 23.10.2018 / 15:09

1 answer

0

Use Django Qsessions

Documentation example (README, in the repository):

Logout a user:

for session in user.session_set.all():
    session.delete()

The example does not show where the variable user comes from, but you could do:

user = User.objects.get(username='nomeususario')

Obs.
The documentation itself mentions that django-user-sessions (another django package) has the same functionality.

    
23.10.2018 / 18:10