不知道这是否仍然需要,但想与我分享我的解决方案:
1)安装django-tracking(感谢你的贴士Van Gale Google Maps + GeoIP很棒!)
2)添加此中间件:
from django.contrib.sessions.models import Sessionfrom tracking.models import Visitorfrom datetime import datetimeclass 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 unipre(last_login)==unipre(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)确保它位于VisitorTrackingMiddleware之后,你应该发现当有人新登录时以前的登录会自动被破坏:)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)