Class: ShopifyApp::SessionsController

Inherits:
ActionController::Base
  • Object
show all
Includes:
LoginProtection
Defined in:
app/controllers/shopify_app/sessions_controller.rb

Constant Summary

Constants included from LoginProtection

LoginProtection::ACCESS_TOKEN_REQUIRED_HEADER

Instance Method Summary collapse

Methods included from LoginProtection

#activate_shopify_session, #current_shopify_session, #login_again_if_different_user_or_shop, #shop_session, #shop_session_by_cookie, #shop_session_by_jwt, #signal_access_token_required, #user_session, #user_session_by_cookie, #user_session_by_jwt

Instance Method Details

#createObject



19
20
21
22
# File 'app/controllers/shopify_app/sessions_controller.rb', line 19

def create
  Rails.logger.debug("[ShopifyApp::SessionsController] Authenticating...")
  authenticate
end

#destroyObject



58
59
60
61
62
63
# File 'app/controllers/shopify_app/sessions_controller.rb', line 58

def destroy
  Rails.logger.debug("[ShopifyApp::SessionsController] Resetting session.")
  reset_session
  flash[:notice] = I18n.t('.logged_out')
  redirect_to()
end

#enable_cookiesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/shopify_app/sessions_controller.rb', line 24

def enable_cookies
  Rails.logger.debug("[ShopifyApp::SessionsController] Enabling cookies...")
  return unless validate_shop_presence

  render(:enable_cookies, layout: false, locals: {
    does_not_have_storage_access_url: top_level_interaction_path(
      shop: sanitized_shop_name,
      return_to: params[:return_to]
    ),
    has_storage_access_url: (top_level: true),
    app_target_url: granted_storage_access_path(
      shop: sanitized_shop_name,
      return_to: params[:return_to]
    ),
    current_shopify_domain: current_shopify_domain,
  })
end

#granted_storage_accessObject



47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/shopify_app/sessions_controller.rb', line 47

def granted_storage_access
  Rails.logger.debug("[ShopifyApp::SessionsController] Granted storage access.")
  return unless validate_shop_presence

  session['shopify.granted_storage_access'] = true

  copy_return_to_param_to_session

  redirect_to(return_address_with_params({ shop: @shop }))
end

#newObject



12
13
14
15
16
17
# File 'app/controllers/shopify_app/sessions_controller.rb', line 12

def new
  if sanitized_shop_name.present?
    Rails.logger.debug("[ShopifyApp::SessionsController] Sanitized shop name present. Authenticating...")
    authenticate
  end
end

#top_level_interactionObject



42
43
44
45
# File 'app/controllers/shopify_app/sessions_controller.rb', line 42

def top_level_interaction
  @url = (top_level: true)
  validate_shop_presence
end