Sha256: 564d4343363641f3b4b4450767eba53a5bb84383d8cc81a503cd4c73e3766241

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

Contents

module Outpost
  module Controller
    module Authentication
      extend ActiveSupport::Concern

      included do
        before_filter :require_login
        helper_method :current_user
      end

      # Public: The currently logged-in user.
      #
      # Returns Outpost.user_class instance.
      def current_user
        begin
          @current_user ||= Outpost.user_class
            .where(can_login: true).find(session[:user_id])
        rescue ActiveRecord::RecordNotFound
          session[:user_id]   = nil
          @current_user       = nil
        end
      end

      # Private: Callback to require login.
      #
      # Returns nothing.
      def require_login
        if !current_user
          session[:return_to] = request.fullpath
          redirect_to outpost.login_path and return false
        end
      end
    end # Authentication
  end # Controller
end # Outpost

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 lib/outpost/controller/authentication.rb
outpost-cms-0.1.3 lib/outpost/controller/authentication.rb
outpost-cms-0.1.2 lib/outpost/controller/authentication.rb
outpost-cms-0.1.1 lib/outpost/controller/authentication.rb
outpost-cms-0.1.0 lib/outpost/controller/authentication.rb