Sha256: 057cee7930576ff7ad87f1e264aa5ac31ccefacad608186866f1716cbe615ee0

Contents?: true

Size: 657 Bytes

Versions: 3

Compression:

Stored size: 657 Bytes

Contents

module TkhAuthenticationActionControllerExtension
  def self.included(base)
    base.send(:include, InstanceMethods) 
    # base.before_filter :authenticate
    # base.after_filter :my_method_2
  end

  module InstanceMethods
    def current_user
      @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
    end

    def authenticate
      redirect_to login_url, alert: t('authentication.warning.login_needed') if current_user.nil?
    end
    
    def authenticate_with_admin
      redirect_to root_url, alert: t('authentication.warning.restricted_access') unless current_user && current_user.admin?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tkh_authentication-0.0.5 lib/tkh_authentication/tkh_authentication_action_controller_extension.rb
tkh_authentication-0.0.4 lib/tkh_authentication/tkh_authentication_action_controller_extension.rb
tkh_authentication-0.0.3 lib/tkh_authentication/tkh_authentication_action_controller_extension.rb