Files
danbooru/app/controllers/sessions_controller.rb
evazion 2e9f4dc2f4 controllers: refactor rate limits.
Refactor controllers so that endpoint rate limits are declared locally,
with the endpoint, instead of globally, in a single method in ApplicationController.

This way an endpoint's rate limit is declared in the same file as the
endpoint itself.

This is so we can add fine-grained rate limits for certain GET requests.
Before rate limits were only for non-GET requests.
2021-12-10 01:46:01 -06:00

36 lines
829 B
Ruby

class SessionsController < ApplicationController
respond_to :html, :json
skip_forgery_protection only: :create, if: -> { !request.format.html? }
rate_limit :create, rate: 1.0/1.minute, burst: 10
def new
@user = User.new
end
def confirm_password
end
def create
name, password, url = params.fetch(:session, params).slice(:name, :password, :url).values
user = SessionLoader.new(request).login(name, password)
if user
url = posts_path unless url&.start_with?("/")
respond_with(user, location: url)
else
flash.now[:notice] = "Password was incorrect"
raise SessionLoader::AuthenticationFailure
end
end
def destroy
SessionLoader.new(request).logout
redirect_to(posts_path, :notice => "You are now logged out")
end
def sign_out
destroy
end
end