Sha256: e304e64f52a7c549f8cd828e3a5b96197d361246beff03d759d8773ac182f3d4

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

module DiscoApp::Concerns::AuthenticatedController
  extend ActiveSupport::Concern

  included do
    before_action :login_again_if_different_shop
    before_action :shopify_shop
    before_action :check_installed
    before_action :check_current_subscription
    before_action :check_active_charge
    around_filter :shopify_session
    layout 'embedded_app'
  end

  private

    def shopify_shop
      if shop_session
        @shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.url)
      else
        redirect_to_login
      end
    end

    def check_installed
      if @shop.awaiting_install? or @shop.installing?
        redirect_if_not_current_path disco_app.installing_path
        return
      end
      if @shop.awaiting_uninstall? or @shop.uninstalling?
        redirect_if_not_current_path disco_app.uninstalling_path
        return
      end
      unless @shop.installed?
        redirect_if_not_current_path disco_app.install_path
      end
    end

    def check_current_subscription
      unless @shop.current_subscription?
        redirect_if_not_current_path disco_app.new_subscription_path
      end
    end

    def check_active_charge
      if @shop.current_subscription? and @shop.current_subscription.requires_active_charge? and not @shop.current_subscription.active_charge?
        redirect_if_not_current_path disco_app.new_subscription_charge_path(@shop.current_subscription)
      end
    end

    def redirect_if_not_current_path(target)
      if request.path != target
        redirect_to target
      end
    end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
disco_app-0.8.8 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.8.9 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.0 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.1 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.2 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.3 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.4 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.5 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.6 app/controllers/disco_app/concerns/authenticated_controller.rb
disco_app-0.9.7 app/controllers/disco_app/concerns/authenticated_controller.rb