From 23d0cd4b55dea7f31079503b8486b8096699d6e5 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 8 Jul 2018 22:52:40 +0200 Subject: [PATCH] Log an audit message when a user successfully logs in --- calsocial/security.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/calsocial/security.py b/calsocial/security.py index 7c9310a..7a45923 100644 --- a/calsocial/security.py +++ b/calsocial/security.py @@ -18,6 +18,7 @@ """ from flask import current_app +from flask_login.signals import user_logged_in from flask_security import Security, AnonymousUser as BaseAnonymousUser security = Security() @@ -33,3 +34,13 @@ class AnonymousUser(BaseAnonymousUser): """ return current_app.timezone + + +@user_logged_in.connect +def login_handler(app, user): + """Signal handler to be called when a user successfully logs in + """ + + from .models import AuditLog + + AuditLog.log(user, AuditLog.TYPE_LOGIN_SUCCESS)