Created
April 20, 2014 03:41
-
-
Save zackchandler/11104388 to your computer and use it in GitHub Desktop.
shopify_app_gem_monkey_patch.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ShopifyApp::LoginProtection | |
def shopify_session | |
if shop_session | |
begin | |
# session[:shopify] set in LoginController#show | |
ShopifyAPI::Base.activate_session(shop_session) | |
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 | |
if session[:shopify_shop] && session[:shopify_token] | |
session[:shopify] = ShopifyAPI::Session.new(session[:shopify_shop], session[:shopify_token]) | |
else | |
session[:shopify] | |
end | |
end | |
protected | |
def close_session | |
session[:shopify] = nil | |
session[:shopify_shop] = nil | |
session[:shopify_token] = nil | |
redirect_to login_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment