User session tracking #93587
@ -28,19 +28,19 @@ def process_new_login(sender, request, user, **kwargs):
|
|||||||
user.login_count = F("login_count") + 1
|
user.login_count = F("login_count") + 1
|
||||||
fields = {"login_count"}
|
fields = {"login_count"}
|
||||||
|
|
||||||
|
user_session, _ = models.UserSession.update_or_create_from_request(request, user)
|
||||||
# Only move 'current' to 'last' login IP if the IP address is different.
|
# Only move 'current' to 'last' login IP if the IP address is different.
|
||||||
request_ip = utils.get_client_ip(request)
|
request_ip = utils.get_client_ip(request)
|
||||||
if request_ip and user.current_login_ip != request_ip:
|
if request_ip and user.current_login_ip != request_ip:
|
||||||
user.last_login_ip = F("current_login_ip")
|
user.last_login_ip = F("current_login_ip")
|
||||||
user.current_login_ip = request_ip
|
user.current_login_ip = request_ip
|
||||||
fields.update({"last_login_ip", "current_login_ip"})
|
fields.update({"last_login_ip", "current_login_ip"})
|
||||||
try:
|
if user.has_confirmed_email:
|
||||||
email.send_new_user_session(request.session.create_model_instance({}))
|
try:
|
||||||
except Exception:
|
email.send_new_user_session(user_session)
|
||||||
Oleg-Komarov marked this conversation as resolved
|
|||||||
log.exception('failed to send a new user session email')
|
except Exception:
|
||||||
|
log.exception('failed to send a new user session email')
|
||||||
user.save(update_fields=fields)
|
user.save(update_fields=fields)
|
||||||
models.UserSession.update_or_create_from_request(request, user)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(m2m_changed)
|
@receiver(m2m_changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user
should be a call of a task