How can I detect multiple logins into a Django web application from different locations?

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

时间: 2024-10-11 13:15:11

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

mvc:resources

springmvc 配置静态文件 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources 15.12.4 mvc:resources This tag allows static resource requests following a particular URL pattern to be served by a Resour

Spring MVC如何访问到静态的文件,如jpg,js,css?

如果你的DispatcherServlet拦截 *.do这样的URL,就不存在访问不到静态资源的问题.如果你的DispatcherServlet拦截"/",拦截了所有的请求,同时对*.js,*.jpg的访问也就被拦截了. 目的:可以正常访问静态文件,不要找不到静态文件报404. 方案一:激活Tomcat的defaultServlet来处理静态文件 Xml代码 <servlet-mapping>  <servlet-name>default</servlet

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

原文地址:http://www.javacodegeeks.com/2013/07/spring-jta-multiple-resource-transactions-in-tomcat-with-atomikos-example.html In this tutorial we shall show you how to implement JTA multiple resource transactions in a Tomcat server, using Atomikos Transac

Oracle Applications Multiple Organizations Access Control for Custom Code

文档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code Checked for relevance on 12-JAN-2011 See Change Record This document discusses how to update the customization code that is affected by the access co

Supporting Multiple Screens(支持Android各种屏幕尺寸)

原文链接 本文翻译自Supporting Multiple Screens. 目前我这篇翻译应该是最全,最完整的官方文档翻译,转载我的翻译请联系本人,标明出处. Supporting Multiple Screens Android runs on a variety of devices that offer different screen sizes and densities. For applications, the Android system provides a consist

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-Pass-Multiple-Models Introduction In this article, we will discuss how to choose the most suitable way to pass multiple models from controller to vie

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

问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰色的,不能使用. 当你把鼠标放到那个按钮上悬停,会出现一条提示信息说: This control is currently disabled. You might not have the right permission level to use this, you might need to s

【ASP.NET Identity教程】ASP.NET Identity入门

注:本文是[ASP.NET Identity系列教程]的第一篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序的用户管理,以及实现应用程序的认证与授权等相关技术,译者希望本系列教程成为掌握ASP.NET Identity技术的一份完整而有价值的资料,希望得到广大园友的高度推荐. 13 Getting Started with Identity 13 Identity入门 Identity is a new

Cross-Domain Security For Data Vault

Cross-domain security for data vault is described. At least one database is accessible from a plurality of network domains, each network domain having a domain security level. The at least one database includes at least one partitioned data table tha