Commit 681ddb5a authored by ibuler's avatar ibuler

[Bugfix] for login ip

parent 29061aa0
...@@ -128,7 +128,7 @@ class UserAuthApi(APIView): ...@@ -128,7 +128,7 @@ class UserAuthApi(APIView):
user_agent = request.data.get('HTTP_USER_AGENT', '') user_agent = request.data.get('HTTP_USER_AGENT', '')
if not login_ip: if not login_ip:
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR').split() x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '').split(',')
if x_forwarded_for: if x_forwarded_for:
login_ip = x_forwarded_for[0] login_ip = x_forwarded_for[0]
else: else:
......
...@@ -180,6 +180,7 @@ def validate_ip(ip): ...@@ -180,6 +180,7 @@ def validate_ip(ip):
def write_login_log(username, type='', ip='', user_agent=''): def write_login_log(username, type='', ip='', user_agent=''):
if not (ip and validate_ip(ip)): if not (ip and validate_ip(ip)):
ip = ip[:15]
city = "Unknown" city = "Unknown"
else: else:
city = get_ip_city(ip) city = get_ip_city(ip)
......
...@@ -53,7 +53,7 @@ class UserLoginView(FormView): ...@@ -53,7 +53,7 @@ class UserLoginView(FormView):
if not self.request.session.test_cookie_worked(): if not self.request.session.test_cookie_worked():
return HttpResponse(_("Please enable cookies and try again.")) return HttpResponse(_("Please enable cookies and try again."))
auth_login(self.request, form.get_user()) auth_login(self.request, form.get_user())
x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR', '').split() x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR', '').split(',')
if x_forwarded_for: if x_forwarded_for:
login_ip = x_forwarded_for[0] login_ip = x_forwarded_for[0]
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment