Skip to content

Commit

Permalink
Merge pull request #500 from EverythingMe/feature/login_events
Browse files Browse the repository at this point in the history
Feature: add event for users logining in
  • Loading branch information
arikfr committed Jul 20, 2015
2 parents 4b8a94e + 3dc9c84 commit d512cd0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions redash/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import logging

from flask.ext.login import LoginManager
from flask.ext.login import user_logged_in

from redash import models, settings, google_oauth, saml_auth
from redash.tasks import record_event

login_manager = LoginManager()
logger = logging.getLogger('authentication')
Expand Down Expand Up @@ -73,6 +75,17 @@ def api_key_load_user_from_request(request):
return user


def log_user_logged_in(app, user):
event = {
'user_id': user.id,
'action': 'login',
'object_type': 'redash',
'timestamp': int(time.time()),
}

record_event.delay(event)


def setup_authentication(app):
login_manager.init_app(app)
login_manager.anonymous_user = models.AnonymousUser
Expand All @@ -81,6 +94,8 @@ def setup_authentication(app):
app.register_blueprint(google_oauth.blueprint)
app.register_blueprint(saml_auth.blueprint)

user_logged_in.connect(log_user_logged_in)

if settings.AUTH_TYPE == 'hmac':
login_manager.request_loader(hmac_load_user_from_request)
elif settings.AUTH_TYPE == 'api_key':
Expand Down

0 comments on commit d512cd0

Please sign in to comment.