Class: LoginController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- LoginController
- Defined in:
- lib/generators/shopify_app/templates/app/controllers/login_controller.rb
Instance Method Summary collapse
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 "/auth/shopify?shop=#{params[:shop].to_s.strip}" else redirect_to return_address end end |
#finalize ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 19 def finalize if response = request.env['omniauth.auth'] sess = ShopifyAPI::Session.new(params['shop'], response['credentials']['token']) session[:shopify] = sess flash[:notice] = "Logged in" 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 authenticate_path(:shop => params[:shop]) end end |
#logout ⇒ Object
32 33 34 35 36 37 |
# File 'lib/generators/shopify_app/templates/app/controllers/login_controller.rb', line 32 def logout session[:shopify] = nil flash[:notice] = "Successfully logged out." redirect_to :action => 'index' end |