Skip to content

Commit

Permalink
Remove redirect_to_with_fallback, format response
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammadk committed Dec 15, 2016
1 parent 4c82c1b commit e2ae588
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
48 changes: 24 additions & 24 deletions lib/shopify_app/login_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def redirect_to_login
head :unauthorized
else
session[:return_to] = request.fullpath if request.get?
redirect_to_with_fallback main_or_engine_login_url(shop: params[:shop])
redirect_to main_or_engine_login_url(shop: params[:shop])
end
end

def close_session
session[:shopify] = nil
session[:shopify_domain] = nil
redirect_to_with_fallback main_or_engine_login_url(shop: params[:shop])
redirect_to main_or_engine_login_url(shop: params[:shop])
end

def main_or_engine_login_url(params = {})
Expand All @@ -56,31 +56,31 @@ def main_or_engine_login_url(params = {})
end

def fullpage_redirect_to(url)
render inline: redirection_javascript(url)
end

def redirect_to_with_fallback(url)
render inline: redirection_javascript(url), status: 302, location: url
if ShopifyApp.configuration.embedded_app?
render inline: redirection_javascript(url)
else
redirect_to url
end
end

def redirection_javascript(url)
%Q(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Redirecting…</title>
<script type="text/javascript">
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: window.location.origin + #{url.to_json} }
});
window.parent.postMessage(data, "https://#{sanitized_shop_name}");
</script>
</head>
<body>
</body>
</html>
%(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Redirecting…</title>
<script type="text/javascript">
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: window.location.origin + #{url.to_json} }
});
window.parent.postMessage(data, "https://#{sanitized_shop_name}");
</script>
</head>
<body>
</body>
</html>
)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/shopify_app/sessions_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def callback
install_scripttags

flash[:notice] = I18n.t('.logged_in')
redirect_to_with_fallback return_address
redirect_to return_address
else
flash[:error] = I18n.t('could_not_log_in')
redirect_to_with_fallback login_url
redirect_to login_url
end
end

def destroy
session[:shopify] = nil
session[:shopify_domain] = nil
flash[:notice] = I18n.t('.logged_out')
redirect_to_with_fallback login_url
redirect_to login_url
end

protected
Expand All @@ -42,7 +42,7 @@ def authenticate
if sanitized_shop_name.present?
fullpage_redirect_to "#{main_app.root_path}auth/shopify?shop=#{sanitized_shop_name}"
else
redirect_to_with_fallback return_address
redirect_to return_address
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class SessionsControllerTest < ActionController::TestCase

test "#new should authenticate the shop if the shop param exists non embedded" do
ShopifyApp.configuration.embedded_app = false
shopify_domain = 'my-shop.myshopify.com'
auth_url = '/auth/shopify?shop=my-shop.myshopify.com'
get :new, shop: 'my-shop'
assert_redirected_to_authentication(shopify_domain, response)
assert_redirected_to auth_url
end

test "#new should trust the shop param over the current session" do
Expand Down

0 comments on commit e2ae588

Please sign in to comment.