Sha256: 603c97ea3df04cedc2eae3c0f9af84285b16e673413220f3dd6989371ad6d565

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

puts "CommonApplicationController Concern from ThecoreUiCommons"
require 'active_support/concern'

module ConcernCommonApplicationController
  extend ActiveSupport::Concern
  
  included do
    # protect_from_forgery prepend: true
    protect_from_forgery except: :sign_in,  prepend: true
    
    rescue_from CanCan::AccessDenied do |exception| 
      redirect_to main_app.root_url, alert: exception.message 
    end
    
    before_action :store_user_location!, if: :storable_location?
    before_action :reject_locked!, if: :devise_controller?
    
    # Auto-sign out locked users
    def reject_locked!
      if !current_user.blank? && current_user.locked?
        Rails.logger.debug " - Cleaning session"
        sign_out current_user
        user_session = nil
        current_user = nil
        flash[:alert] = "Your account is locked."
        flash[:notice] = nil
        redirect_to root_url
      end
    end
    
    # Its important that the location is NOT stored if:
    # - The request method is not GET (non idempotent)
    # - The request is handled by a Devise controller such as 
    #     Devise::SessionsController as that could cause an 
    #     infinite redirect loop.
    # - The request is an Ajax request as this can lead to very unexpected 
    #     behaviour.
    def storable_location?
      request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
    end
    
    def store_user_location!
      # :user is the scope we are authenticating
      store_location_for(:user, request.fullpath)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
thecore_ui_commons-3.2.11 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.10 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.9 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.8 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.7 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.6 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.5 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.4 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.3 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.2 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.1 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.2.0 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.1.11 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.1.10 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.1.9 config/initializers/concern_common_application_controller.rb
thecore_ui_commons-3.1.8 config/initializers/concern_common_application_controller.rb