I came back to tell you how I solved my problem.
Being new still in Django I had to solve my way and following the tips that were given to me in this forum.
WHAT I DID
Knowing the user’s email I got his id.
user = User.objects.get(username = mail)
user_id = user.id
Then I searched all the sessions and with the for
I looked for the session that had this one, but for that I had to decode before.
`sessoes = Session.objects.all()
for k in sessoes:
z = k.get_decoded() #decodifica e pega a sessao
if(z['_auth_user_id'] == str(user_id)): # compara sessaoes encontradas com a sessao do usuario que tenta logar`
Then what I did was just delete the session that had that id.
NOTE: Also includes in Settings SESSION_EXPIRE_AT_BROWSER_CLOSE = True
so that the session expires when the browser is closed.
Thank you all!
Are the sessions saved in a bank? If they are, just check if the user is logged in, if he is already logged in, do not allow the new login. or if he tries to log in delete sessions with his session table id
– Vinicius De Jesus
This certainly helped a lot. But I’m still having a hard time getting a session from a specific user. I’ve looked through the comic book to see if I can find any connection, but I can’t find.
– Álvaro Antônio
Are you being saved to DB? if so:
select count(*) from sessoes where user_id = 'id'
if the answer is > 0 (You are logged in!), do not let it log in!– Vinicius De Jesus