Sha256: 61cd95b475e5d689f0e3135d700965bf565625789c0423bdb1340f6262b26718

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

class ApplicationController < ActionController::Base
  before_action :set_current_request_details
  before_action :authenticate
  <%- if options.sudoable? %>
  def require_sudo
    unless Current.session.sudo?
      redirect_to new_sessions_sudo_path(proceed_to_url: request.url)
    end
  end
  <%- end -%>
  <%- if options.lockable? %>
  def require_lock(wait: 1.hour, attempts: 10)
    counter = Kredis.counter("require_lock:#{request.remote_ip}:#{params[:controller]}:#{params[:action]}", expires_in: wait)
    counter.increment

    if counter.value > attempts
      redirect_to new_identity_password_reset_path, alert: "You've exceeded the maximum number of attempts"
    end
  end
  <%- end -%>

  private
    def authenticate
      if session = Session.find_by_id(cookies.signed[:session_token])
        Current.session = session
      else
        redirect_to sign_in_path
      end
    end

    def set_current_request_details
      Current.user_agent = request.user_agent
      Current.ip_address = request.ip
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authentication-zero-2.14.0 lib/generators/authentication/templates/controllers/html/application_controller.rb.tt