mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
502 B
19 lines
502 B
# -*- 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):
|
|
from audits.models import UserLoginLog
|
|
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})
|
|
UserLoginLog.objects.create(**kwargs)
|
|
|