Sha256: d5d97d2884862c08293641652294847c8f7a34a5e24b65b99bbe1e1aa95a4af2
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
class SessionsController < ApplicationController def new authenticate if params[:shop].present? end def create authenticate end def show 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 else flash[:error] = "Could not log in to Shopify store." redirect_to :action => 'new' end end def destroy session[:shopify] = nil flash[:notice] = "Successfully logged out." redirect_to :action => 'new' end protected def authenticate if shop_name = sanitize_shop_param(params) redirect_to "/auth/shopify?shop=#{shop_name}" else redirect_to return_address end end def return_address session[:return_to] || root_url end def sanitize_shop_param(params) return unless params[:shop].present? name = params[:shop].to_s.strip name += '.myshopify.com' if !name.include?("myshopify.com") && !name.include?(".") name.gsub!('https://', '').sub('http://', '') u = URI("http://#{name}") u.host.ends_with?(".myshopify.com") ? u.host : nil end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shopify_app-4.4.2 | lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb |