Compare commits

...

2 Commits

Author SHA1 Message Date
ibuler
79600e25f1 fix: 修复数据库连接没有关闭的问题 2021-11-18 16:34:11 +08:00
feng626
2604f35bb8 perf: 异地登陆去掉本地判断 2021-11-02 21:10:56 +08:00
2 changed files with 11 additions and 3 deletions

View File

@@ -59,6 +59,10 @@ def check_different_city_login(user, request):
else:
city = get_ip_city(ip) or DEFAULT_CITY
last_user_login = UserLoginLog.objects.filter(username=user.username, status=True).first()
if last_user_login and last_user_login.city != city:
DifferentCityLoginMessage(user, ip, city).publish_async()
city_white = ['LAN', ]
if city not in city_white:
last_user_login = UserLoginLog.objects.exclude(city__in=city_white) \
.filter(username=user.username, status=True).first()
if last_user_login and last_user_login.city != city:
DifferentCityLoginMessage(user, ip, city).publish_async()

View File

@@ -2,6 +2,7 @@ import threading
import json
from redis.exceptions import ConnectionError
from channels.generic.websocket import JsonWebsocketConsumer
from django.db import close_old_connections
from common.utils import get_logger
from .site_msg import SiteMessageUtil
@@ -65,8 +66,11 @@ class SiteMsgWebsocket(JsonWebsocketConsumer):
logger.debug('Decode json error: ', e)
except ConnectionError:
logger.debug('Redis chan closed')
finally:
close_old_connections()
def disconnect(self, close_code):
if self.chan is not None:
self.chan.close()
self.close()
close_old_connections()