1) Install django-tracking (thankyou for that tip Van Gale Google Maps + GeoIP is amazing!)

2) Add this middleware:

from django.contrib.sessions.models import Session
from tracking.models import Visitor
from datetime import datetime class UserRestrictMiddleware(object):
"""
Prevents more than one user logging in at once from two different IPs
"""
def process_request(self, request):
ip_address = request.META.get('REMOTE_ADDR','')
try:
last_login = request.user.last_login
except:
last_login = 0
if unicode(last_login)==unicode(datetime.now())[:19]:
previous_visitors = Visitor.objects.filter(user=request.user).exclude(ip_address=ip_address)
for visitor in previous_visitors:
Session.objects.filter(session_key=visitor.session_key).delete()
visitor.user = None
visitor.save()

3) Make sure it goes after the VisitorTrackingMiddleware and you should find previous logins are automatically bumped when someone new logs in :)

转自: http://stackoverflow.com/questions/821870/how-can-i-detect-multiple-logins-into-a-django-web-application-from-different-lo

How can I detect multiple logins into a Django web application from different locations?的更多相关文章

  1. multiple web application host under the same website on IIS (authentication mode)

    第一种方式,修改forms的name how to set the forms authentication cookie path assume you have already solved th ...

  2. mvc:resources

    springmvc 配置静态文件 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mv ...

  3. Spring mvc 中 DispatcherServlet 的学习和理解

    上图表示当客户请求来到时,spring架构作出响应的流程,可以从图中看到看到请求分发的中心就是 DispatcherServlet 类,DispatcherServlet的任务是将请求发送给Sprin ...

  4. Spring JTA multiple resource transactions in Tomcat with Atomikos example--转载

    原文地址:http://www.javacodegeeks.com/2013/07/spring-jta-multiple-resource-transactions-in-tomcat-with-a ...

  5. Oracle Applications Multiple Organizations Access Control for Custom Code

    档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...

  6. 多文档上传(upload multiple documents)功能不能使用怎么办?

    问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...

  7. Struts – Multiple configuration files example

    Many developers like to put all Struts related stuff (action, form) into a single Struts configurati ...

  8. 【原创】InputStream has already been read - do not use InputStreamResource if a stream needs to be read multiple times

    一.背景 基于SpringBoot 构建了一个http文件下载服务,检查tomcat access 发现偶尔出现500 状态码的请求,检查抛出的异常堆栈 2019-03-20 10:03:14,273 ...

  9. How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC

    Snesh Prajapati, 8 Dec 2014 http://www.codeproject.com/Articles/717941/How-to-Choose-the-Best-Way-to ...

随机推荐

  1. LAMP----linux+apache+mysql+php详细安装步骤之一APACHE篇(openldap等)

    LAMP----linux+apache+mysql+php详细安装步骤之一APACHE篇(openldap等) linux详细版本为RHEL5.3 [root@localhost mail]# un ...

  2. ArcMAP中如何将16位保存的卫星底图,转变为8位表示

    首先说明,这种转换将会去除影像的投影像素的定义,并在转换后变为黑色的部分.16位的存储,一方面也是定义透明非数据像素点表示的方便.但是这种定义直接加大了影像的大小,不便于与CAD等软件进行交换数据.

  3. squid.conf 的cache_peer 详解

    通过squid.conf配置文件中的cache_peer选项来配置代理服务器阵列,通过其他的选项来控制选择代理伙伴的方法.Cache_peer的使用格式如下: cache_peer hostname ...

  4. java 文件上传数据库

    存储文件的数据库类型: 1.oracle :Blob,bfile类型 2.mysql:longblob类型 3.sqlserver :varbinary(Max)类型 文件都是以二进制流存入数据库的, ...

  5. hive启动报错:system:java.io.tmpdir等

    解决方法:在hive-site.xml中添加 <property>    <name>system:java.io.tmpdir</name>    <val ...

  6. Hadoop部署记录

    1.准备Linux环境 1.0先将虚拟机的网络模式选为NAT 1.1修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=node1 ### ...

  7. [转载]SecureCRT 绝佳配色方案, 保护你的眼睛

    FROM:http://blog.csdn.net/zklth/article/details/8937905 SecureCRT 绝佳配色方案, 保护你的眼睛   关键词:SecureCRT配色,  ...

  8. defer,panic,recover

    Go语言不支持传统的 try…catch…finally 这种异常,因为Go语言的设计者们认为,将异常与控制结构混在一起会很容易使得代码变得混乱.因为开发者很容易滥用异常,甚至一个小小的错误都抛出一个 ...

  9. redis有序集合的一个应用

    一.需求 记录用户uid和上次操作时间;并清除5分钟以前的数据.用redis的一个key实现.本打算用hash,但hash类型在过期5分钟以前的数据时颇为麻烦. 二.代码实现 class LastLo ...

  10. Android控件常见属性

    1.宽/高android:layout_width android:layout_height// 取值match_parent //匹配父控件wrap_content //自适应,根据内容 如果指定 ...