User session tracking #93587

Merged
Oleg-Komarov merged 18 commits from user-session into main 2024-08-02 16:04:09 +02:00
Showing only changes of commit 5b78784144 - Show all commits

View File

@ -28,19 +28,19 @@ def process_new_login(sender, request, user, **kwargs):
user.login_count = F("login_count") + 1
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.
request_ip = utils.get_client_ip(request)
if request_ip and user.current_login_ip != request_ip:
user.last_login_ip = F("current_login_ip")
user.current_login_ip = request_ip
fields.update({"last_login_ip", "current_login_ip"})
try:
email.send_new_user_session(request.session.create_model_instance({}))
except Exception:
log.exception('failed to send a new user session email')
if user.has_confirmed_email:
try:
email.send_new_user_session(user_session)
Oleg-Komarov marked this conversation as resolved
Review

should be a call of a task

should be a call of a task
except Exception:
log.exception('failed to send a new user session email')
user.save(update_fields=fields)
models.UserSession.update_or_create_from_request(request, user)
@receiver(m2m_changed)