Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add event for users logining in #500

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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