<commit_before>module ShopifyApp::LoginProtection
  extend ActiveSupport::Concern
  
  included do
    rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
  end
  
  def shopify_session
    if session[:shopify]
      begin
        # session[:shopify] set in LoginController#finalize
        ShopifyAPI::Base.activate_session(session[:shopify])
        yield
      ensure 
        ShopifyAPI::Base.clear_session
      end
    else
      session[:return_to] = request.fullpath if request.get?
      redirect_to login_path
    end
  end
  
  def shop_session
    session[:shopify]
  end
  
  protected
  
  def close_session
    session[:shopify] = nil
    redirect_to login_path
  end
end
<commit_msg>automatic login for application links<commit_after>module ShopifyApp::LoginProtection
  extend ActiveSupport::Concern
  
  included do
    rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
  end
  
  def shopify_session
    if session[:shopify]
      begin
        # session[:shopify] set in LoginController#show
        ShopifyAPI::Base.activate_session(session[:shopify])
        yield
      ensure 
        ShopifyAPI::Base.clear_session
      end
    else
      session[:return_to] = request.fullpath if request.get?
      redirect_to login_path(shop: params[:shop])
    end
  end
  
  def shop_session
    session[:shopify]
  end
  
  protected
  
  def close_session
    session[:shopify] = nil
    redirect_to login_path
  end
end

{'fraction_non_alphanumeric': 0.0676132521974307, 'fraction_numerical': 0.0, 'mean_word_length': 3.0217391304347827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '110419', 'n_tokens_mistral': 442, 'n_tokens_neox': 438, 'n_words': 99}