forked from e621ng/e621ng
[Prod] Add instrumentation to login attempts
This commit is contained in:
parent
728a8caa60
commit
e3256bb313
@ -5,15 +5,18 @@ class SessionsController < ApplicationController
|
||||
|
||||
def create
|
||||
if RateLimiter.check_limit("login:#{request.remote_ip}", 15, 12.hours)
|
||||
DanbooruLogger.add_attributes("user.login" => "rate_limited")
|
||||
return redirect_to(new_session_path, :notice => "Username/Password was incorrect")
|
||||
end
|
||||
session_creator = SessionCreator.new(session, cookies, params[:name], params[:password], request.remote_ip, params[:remember], request.ssl?)
|
||||
|
||||
if session_creator.authenticate
|
||||
url = params[:url] if params[:url] && params[:url].start_with?("/") && !params[:url].start_with?("//")
|
||||
DanbooruLogger.add_attributes("user.login" => "success")
|
||||
redirect_to(url || posts_path, :notice => "You are now logged in")
|
||||
else
|
||||
RateLimiter.hit("login:#{request.remote_ip}", 6.hours)
|
||||
DanbooruLogger.add_attributes("user.login" => "fail")
|
||||
redirect_to(new_session_path, :notice => "Username/Password was incorrect")
|
||||
end
|
||||
end
|
||||
|
@ -13,8 +13,12 @@ class DanbooruLogger
|
||||
end
|
||||
|
||||
def self.initialize(user, remote_ip)
|
||||
add_attributes("user.id" => user.id, "user.name" => user.name, "user.ip" => remote_ip)
|
||||
end
|
||||
|
||||
def self.add_attributes(**)
|
||||
return unless defined?(::NewRelic)
|
||||
|
||||
::NewRelic::Agent.add_custom_attributes({ "user.id" => user.id, "user.name" => user.name, "user.ip" => remote_ip })
|
||||
::NewRelic::Agent.add_custom_attributes(**)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user