Created
February 21, 2012 04:50
-
-
Save travishaynes/1873754 to your computer and use it in GitHub Desktop.
Shopify Sessions Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
skip_authorization_check | |
def new | |
unless params[:shop].present? | |
@shop = Shop.new | |
return | |
end | |
@session = ShopifyAPI::Session.new(params[:shop], params[:t], params) | |
respond_to do |format| | |
if @session.valid? | |
session[:shopify] = @session | |
@shop = Shop.find_or_create_by_domain(params[:shop]) | |
name = shopify_session { ShopifyAPI::Shop.current.name } | |
@shop.update_attributes(token: params[:t], name: name) | |
return_address = session[:return_to] || root_path | |
session.delete :return_to | |
format.html { redirect_to return_address } | |
else | |
flash.now.alert = "Shopify authentication failed." | |
format.html { render action: "new" } | |
end | |
end | |
end | |
def create | |
@session = ShopifyAPI::Session.new(params[:shop][:domain]) | |
permission_url = @session.create_permission_url | |
respond_to do |format| | |
format.html { redirect_to permission_url } | |
end | |
end | |
def destroy | |
if session[:shopify] | |
reset_session | |
redirect_to root_path, :notice => 'Successfully logged out.' | |
else | |
redirect_to root_path, :alert => 'You are not signed in.' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment