Class: LoginController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- LoginController
- Defined in:
- lib/generators/shopify_app/templates/app/controllers/login_controller.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#finalize ⇒ Object
Shopify redirects the logged-in user back to this action along with the authorization token t.
- #index ⇒ Object
- #logout ⇒ Object
Instance Method Details
#authenticate ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 11 def authenticate if params[:shop].present? redirect_to ShopifyAPI::Session.new(params[:shop].to_s). else redirect_to return_address end end |
#finalize ⇒ Object
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.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 24 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 |
#index ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 2 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? redirect_to :controller => 'login', :action => "authenticate", :shop => params[:shop] end end |
#logout ⇒ Object
38 39 40 41 42 43 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 38 def logout session[:shopify] = nil flash[:notice] = "Successfully logged out." redirect_to :action => 'index' end |