Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Created May 1, 2011 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carolineschnapp/950726 to your computer and use it in GitHub Desktop.
Save carolineschnapp/950726 to your computer and use it in GitHub Desktop.
Remember requested URL when logging in
class LoginController < ApplicationController
def index
# Ask user for their #{shop}.myshopify.com address
# If the #{shop}.myshopify.com address is already provided in the URL, just skip to #authenticate
if params[:shop].present?
# Added next line — Caroline.
session[:return_to] = request.path
# End of Caroline's addition.
redirect_to :controller => 'login', :action => "authenticate", :shop => params[:shop]
end
end
def authenticate
if params[:shop].present?
redirect_to ShopifyAPI::Session.new(params[:shop].to_s).create_permission_url
else
redirect_to return_address
end
end
# Shopify redirects the logged-in user back to this action along with
# the authorization token t.
#
# This token is later combined with the developer's shared secret to form
# the password used to call API methods.
def finalize
shopify_session = ShopifyAPI::Session.new(params[:shop], params[:t], params)
if shopify_session.valid?
session[:shopify] = shopify_session
flash[:notice] = "Logged in to shopify store."
redirect_to return_address
session[:return_to] = nil
else
flash[:error] = "Could not log in to Shopify store."
redirect_to :action => 'index'
end
end
def logout
session[:shopify] = nil
flash[:notice] = "Successfully logged out."
redirect_to :action => 'index'
end
protected
def return_address
session[:return_to] || root_url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment