Sha256: 5af98d01d11d914a5a83d2f2b7f87f13a15eb2e1d5a58403c78d3e33856050a7

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

class ApplicationController < ActionController::Base
  before_action :set_current_request_details
  before_action :authenticate
  <%- if options.sudoable? %>
  def require_sudo
    <%- if omniauthable? -%>
    unless Current.session.sudo? || Current.session.user.provider.present?
    <%- else -%>
    unless Current.session.sudo?
    <%- end -%>
      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 root_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

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-2.16.5 lib/generators/authentication/templates/controllers/html/application_controller.rb.tt
authentication-zero-2.16.4 lib/generators/authentication/templates/controllers/html/application_controller.rb.tt
authentication-zero-2.16.3 lib/generators/authentication/templates/controllers/html/application_controller.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/controllers/html/application_controller.rb.tt