<commit_before>module Concerns::AuthenticationHandler
  extend ActiveSupport::Concern

  included do
    before_filter :require_basic_auth
    before_filter :set_return_to, if: -> { !current_user && params[:redirect_to].present? }
    before_filter :redirect_user_back_after_login, unless: :devise_controller?
    before_filter :configure_permitted_parameters, if: :devise_controller?

    private
    def set_return_to
      if params[:redirect_to].present?
        session[:return_to] = params[:redirect_to]
        flash[:devise_error] = t('devise.failure.unauthenticated')
      end
    end

    def after_sign_in_path_for(resource_or_scope)
      return_to = session[:return_to]
      session[:return_to] = nil
      (return_to || root_path)
    end
<commit_msg>Force base domain with https when accessing device controlelr with subdomain<commit_after>module Concerns::AuthenticationHandler
  extend ActiveSupport::Concern

  included do
    before_filter :require_basic_auth
    before_filter :set_return_to, if: -> { !current_user && params[:redirect_to].present? }
    before_filter :redirect_user_back_after_login, unless: :devise_controller?
    before_filter :configure_permitted_parameters, if: :devise_controller?
    before_filter :force_base_domain_with_ssl, if: :devise_controller?

    private
    def force_base_domain_with_ssl
      if Rails.env.production? && request.subdomain.present? && !ENV['IS_STAGING']
        redirect_to(protocol: 'https', host: ::Configuration[:base_domain])
      end
    end

    def set_return_to
      if params[:redirect_to].present?
        session[:return_to] = params[:redirect_to]
        flash[:devise_error] = t('devise.failure.unauthenticated')
      end
    end

    def after_sign_in_path_for(resource_or_scope)
      return_to = session[:return_to]
      session[:return_to] = nil
      (return_to || root_path)
    end

{'fraction_non_alphanumeric': 0.09037745879851143, 'fraction_numerical': 0.0, 'mean_word_length': 4.31638418079096, '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': '4548990', 'n_tokens_mistral': 584, 'n_tokens_neox': 568, 'n_words': 108}