Sha256: d76ea959ce74780782098365b4a858be2abddaa14d18d9622250dc40aa97869c

Contents?: true

Size: 822 Bytes

Versions: 13

Compression:

Stored size: 822 Bytes

Contents

require "godmin/authentication/sessions_controller"
require "godmin/authentication/user"

module Godmin
  module Authentication
    extend ActiveSupport::Concern

    included do
      before_action :authenticate_admin_user

      helper_method :admin_user
      helper_method :admin_user_signed_in?
    end

    def authenticate_admin_user
      unless admin_user_signed_in? || controller_name == "sessions"
        redirect_to new_session_path, alert: "Authentication needed"
      end
    end

    def admin_user_class
      raise NotImplementedError, "Must define the admin user class"
    end

    def admin_user
      if session[:admin_user_id]
        @admin_user ||= admin_user_class.find_by(id: session[:admin_user_id])
      end
    end

    def admin_user_signed_in?
      admin_user.present?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
godmin-1.3.1 lib/godmin/authentication.rb
godmin-1.3.0 lib/godmin/authentication.rb
godmin-1.2.0 lib/godmin/authentication.rb
godmin-1.1.0 lib/godmin/authentication.rb
godmin-1.0.0 lib/godmin/authentication.rb
godmin-0.12.4 lib/godmin/authentication.rb
godmin-0.12.3 lib/godmin/authentication.rb
godmin-0.12.2 lib/godmin/authentication.rb
godmin-0.12.1 lib/godmin/authentication.rb
godmin-0.12.0 lib/godmin/authentication.rb
godmin-0.11.2 lib/godmin/authentication.rb
godmin-0.11.1 lib/godmin/authentication.rb
godmin-0.11.0 lib/godmin/authentication.rb