Skip to content

Instantly share code, notes, and snippets.

@brissmyr
Last active February 15, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brissmyr/8a40a6f9b271770772412820f728b21b to your computer and use it in GitHub Desktop.
Save brissmyr/8a40a6f9b271770772412820f728b21b to your computer and use it in GitHub Desktop.
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