简体   繁体   English

Django中的注销功能

[英]Logout functionality in django

All 所有

In django project if 2 template windows are opened and if logout is triggered in 1 window the other window cookies are not cleared.How to delete the cookies also so that the logout will be triggered. 在django项目中,如果打开了2个模板窗口,并且如果在1个窗口中触发了注销,则不会清除其他窗口cookie。如何也删除cookie,以便触发注销。

def logout(request):
    //request = redirect('webbie.home.views.loginpage')
    //request.delete_cookie('user_location')
    return auth_logout(request)

Thanks.. 谢谢..

In the cookie you should only store a session key. 在Cookie中,您只应存储会话密钥。 The server then needs to keep track of all session keys and associate expire date/time and user-account with them. 然后,服务器需要跟踪所有会话密钥,并将过期日期/时间和用户帐户与它们相关联。 For every user that logs in they should be given a new session key, though you may allow multiple logins/user-account. 尽管可以允许多个登录名/用户帐户,但应该为每个登录的用户提供一个新的会话密钥。 So when you check if the cookie is valid you need to consult your sever DB and see if you have this session key and that it's valid. 因此,当您检查cookie是否有效时,您需要查阅服务器数据库,并查看您是否具有此会话密钥以及该会话密钥是否有效。 If you now want to "kill" all active sessions for a user-account when one of them logs out you just need to remove all session keys form your servers session key list. 如果您现在想在其中一个注销时“杀死”用户帐户的所有活动会话,则只需从服务器会话密钥列表中删除所有会话密钥。
You should try to not store sensitive data in cookies, a session key is enough and then have the server associate data to this key. 您应该尝试不要在cookie中存储敏感数据,会话密钥就足够了,然后让服务器将数据与该密钥相关联。 Now you have control of the signed in users. 现在,您可以控制已登录的用户。
More Django session info on there documentation: http://docs.djangoproject.com/en/dev/topics/http/sessions/ 有关该文档的更多Django会话信息: http : //docs.djangoproject.com/en/dev/topics/http/sessions/

What do you mean exactly? 你到底是什么意思 You mean if you have to windows open with the same website, and you log out in one window, you are not logged out in the other window? 您的意思是如果您必须在同一网站上打开窗口,并且在一个窗口中注销,那么您是否不在另一个窗口中注销? I doubt that. 我不信。

Of course you are not redirected in the other window to a certain page because you haven't done anything in this specific window. 当然,您不会在另一个窗口中重定向到某个页面,因为在此特定窗口中您还没有做任何事情。 But if you click a link that is only available for logged in users, you should be redirected to a login page. 但是,如果您单击仅对已登录用户可用的链接,则应将您重定向到登录页面。

And no, you cannot detect on client side if a user logged out from another site, at least not without Ajax and some custom checks. 不,您无法在客户端检测到用户是否从另一个站点注销,至少没有Ajax和一些自定义检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM