Last active
February 15, 2018 22:22
-
-
Save brissmyr/8a40a6f9b271770772412820f728b21b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'castle/support/rails' | |
class ApplicationController < ActionController::Base | |
before_action do | |
next unless request.path == '/users/sign_in' | |
email = request.params['user']['email'] | |
password = request.params['user']['password'] | |
user = User.find_by_email(email) | |
if user.present? && user.valid_password?(password) | |
begin | |
verdict = castle.track( | |
event: '$login.succeeded', | |
user_id: user.id, | |
traits: { | |
email: user.email, | |
created_at: user.created_at | |
} | |
) | |
rescue ::Castle::Error => e | |
end | |
else | |
begin | |
castle.track( | |
event: '$login.failed', | |
user_id: user && user.id, | |
traits: { | |
email: email | |
} | |
) | |
rescue ::Castle::Error => e | |
end | |
end | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment