Sha256: fc4e35a1c8ebe3eeb141055bc9b03770cce6a1325cbcb2f92f5f59901b743386

Contents?: true

Size: 709 Bytes

Versions: 4

Compression:

Stored size: 709 Bytes

Contents

module ShopifyApp::LoginProtection
  extend ActiveSupport::Concern
  
  included do
    rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
  end
  
  def shopify_session
    if session[:shopify]
      begin
        # session[:shopify] set in LoginController#show
        ShopifyAPI::Base.activate_session(session[:shopify])
        yield
      ensure 
        ShopifyAPI::Base.clear_session
      end
    else
      session[:return_to] = request.fullpath if request.get?
      redirect_to login_path(shop: params[:shop])
    end
  end
  
  def shop_session
    session[:shopify]
  end
  
  protected
  
  def close_session
    session[:shopify] = nil
    redirect_to login_path
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopify_app-4.2.3 lib/shopify_app/login_protection.rb
shopify_app-4.2.2 lib/shopify_app/login_protection.rb
shopify_app-4.2.1 lib/shopify_app/login_protection.rb
shopify_app-4.2.0 lib/shopify_app/login_protection.rb