Loaning another Jango user

Asked

Viewed 122 times

1

Good Morning I checked user sessions through login and logout: In the login before logging it makes 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 at logout 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 control of sessions, but what I need is that a superuser, can deploy any user, I could not find a solution to this.

1 answer

1

Use Django Qsessions

Example of documentation (README, in the repository):

Logout a user:

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

Example does not show where the variable comes from user, 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 features.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.