jumpserver/apps/authentication/utils.py

19 lines
502 B
Python
Raw Normal View History

2019-02-27 00:45:00 +00:00
# -*- coding: utf-8 -*-
#
from django.utils.translation import ugettext as _
from common.utils import get_ip_city, validate_ip
def write_login_log(*args, **kwargs):
2019-02-28 09:58:53 +00:00
from audits.models import UserLoginLog
2019-02-27 00:45:00 +00:00
default_city = _("Unknown")
ip = kwargs.get('ip', '')
if not (ip and validate_ip(ip)):
ip = ip[:15]
city = default_city
else:
city = get_ip_city(ip) or default_city
kwargs.update({'ip': ip, 'city': city})
2019-02-28 09:58:53 +00:00
UserLoginLog.objects.create(**kwargs)
2019-02-27 00:45:00 +00:00