Rails Plugin & Authentication Issues

Tourist
7 0 1
Is there any documentation for the Rails plugin? For example what the create_permission_url function does? I'm having issues getting the Product ID through the built-in authentication process (login/authenticate and login/finalize), and I would like to avoid re-writing all the code that's been written for the plugin...
0 Likes
Tourist
7 0 1

Nevermind. I’ll just look at the source code (duh).

0 Likes
Tourist
7 0 1

I added a couple lines of code to the shopify_login_protection.rb file to carry the Product ID through the login process as a session variable, for the first time a user visits my app each time. That way my app still knows what product page they came from after they’ve logged in. New code is in bold below:

module ShopifyLoginProtection

def shopify_session
  if session[:shopify]
    begin
      # session[:shopify] set in LoginController#finalize
      ActiveResource::Base.site = session[:shopify].site
      yield
    ensure 
      ActiveResource::Base.site = nil
    end
  else            
    session[:return_to] = request.path
    if params[:id]
        session[:product_id] = params[:id]
    end
    redirect_to :controller => 'login'
  end
end
def current_shop
  session[:shopify]
end

end

0 Likes
Shopify Staff
Shopify Staff
55 0 0

@Josh,

Another option would have been:


module ShopifyLoginProtection

def shopify_session
  if session[:shopify]
    begin
      # session[:shopify] set in LoginController#finalize
      ActiveResource::Base.site = session[:shopify].site
      yield
    ensure 
      ActiveResource::Base.site = nil
    end
  else            
    session[:return_to] = request.request_uri
    redirect_to :controller => 'login'
  end
end
def current_shop
  session[:shopify]
end
end

This would have preserved the product_id param and any other query params that were part of that url.

Jesse Storimer | Shopify Developer | jesse@jadedpixel.com | http://www.jstorimer.com
0 Likes
Highlighted
Tourist
7 0 1

@jesse,

That’s just the code that was in the controller originally, and it didn’t preserve the product ID through the login process, hence this post…

0 Likes
Shopify Staff
Shopify Staff
55 0 0

Thanks for bringing that up Josh. I will update the plugin.

Jesse Storimer | Shopify Developer | jesse@jadedpixel.com | http://www.jstorimer.com
0 Likes