Sha256: df119e1e07dddc5cff018bab79d686094f018e810e890a166a10fb7f36e7f7d1

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Intro
  module Admin
    class ApplicationController < ::Intro::ApplicationController

      protected

      def authenticate
        return if authenticated?

        respond_to do |format|
          format.html { redirect_to unauthenticated_path }
          format.json { render json: { message: t('intro.errors.unauthorized') }, status: :unauthorized }
          format.any  { head :unauthorized }
        end
      end

      def authenticated?
        return @_authenticated if defined?(@_authenticated)

        @_authenticated = has_signed_in? || authenticate_account
      end

      def has_signed_in?
        session[:intro_admin_authenticated] == Intro.config.admin_username_digest
      end

      def authenticate_account
        if Intro.config.admin_authenticate_account.respond_to?(:call)
          instance_exec(&Intro.config.admin_authenticate_account)
        else
          Intro.config.admin_username == params[:username] &&
          Intro.config.admin_password == params[:password]
        end
      end

      def unauthenticated_path
        Intro.config.unauthenticated_admin_path.presence || new_admin_session_path
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
intro-0.4.1 app/controllers/intro/admin/application_controller.rb
intro-0.4.0 app/controllers/intro/admin/application_controller.rb
intro-0.3.0 app/controllers/intro/admin/application_controller.rb
intro-0.2.0 app/controllers/intro/admin/application_controller.rb
intro-0.1.0 app/controllers/intro/admin/application_controller.rb