在 Django 中,如何找到当前登录用户的所有其他活动会话?

发布于 2024-10-01 10:19:40 字数 76 浏览 1 评论 0原文

我想通知用户她也从其他计算机登录,并可以选择关闭这些其他会话。不幸的是,如何在 Django 中做到这一点而不直接破解数据库并不是很明显。

I want to notify a user about her being also logged in from other computer(s), with an option to close these other sessions. Unfortunately it'd not immediately obvious how to do it in Django without hacking the database directly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生路 2024-10-08 10:19:41

您可以通过检查会话是否过期来找到已登录的用户会话。您可以通过以下方式捕获登录的用户会话

Session.objects.filter(expire_date__gte=timezone.now())

you can find the logged in users session by checking the session is expired or not. you can catch the logged in users session by

Session.objects.filter(expire_date__gte=timezone.now())
笔芯 2024-10-08 10:19:40

您可以在访问者 cookie 中存储多个令牌,并根据数据库中的令牌列表验证它们。如果它们是数据库用户配置文件中的多个令牌,您将确保用户是从不同的浏览器登录的。刷新每个令牌将断开用户与其他计算机的连接。

You can store multiple token in visitor cookie and validate them against a list of token in the db. If they are multiple token in the db user profile you will be sure that the user is logged in from different browser. Flusing every token will disconnect the user from other computers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文