<commit_before>User.class_eval do

  if Spree::ClaimOrder::Config[:require_email_confirmation]
    devise :confirmable
  else
    # in case some other extension includes the :confirmable, we add it and remove it
    devise :confirmable
    User.devise_modules.pop
  end

  before_save :reset_confirmed_at_if_email_changed
  after_save :claim_all_unclaimed_orders, :if => Proc.new{ |user| !confirmation_required? }

  def unclaimed_orders
    Order.where("orders.email = ? AND orders.completed_at IS NOT NULL AND orders.user_id != ?", email, id)
  end

  # overrides User.anonymous! in spree_auth
  def self.anonymous!
    token = User.generate_token(:persistence_token)
    user = User.new(:email => <EMAIL>", :password => <PASSWORD>, :password_confirmation => <PASSWORD>, :persistence_token => token)
    user.confirm! if Spree::ClaimOrder::Config[:require_email_confirmation]
    user
  end

  def claim_all_unclaimed_orders
    unclaimed_orders.each do |order|
      order.assign_to_rightful_owner
    end  unless confirmation_required?
  end

  protected

  # overrides Devise::Modules::Confirmable#confirmation_required?
  def confirmation_required?
    User.devise_modules.include?(:confirmable) && !unclaimed_orders.empty? && !confirmed?
  end

  private

  def reset_confirmed_at_if_email_changed
    self.confirmed_at = nil if (!self.new_record? and self.changed.include?("email"))
  end
end<commit_msg>set confirmation_sent_at automatically if there are no unclaimed_orders<commit_after>User.class_eval do

  if Spree::ClaimOrder::Config[:require_email_confirmation]
    devise :confirmable
  else
    # in case some other extension includes the :confirmable, we add it and remove it
    devise :confirmable
    User.devise_modules.pop
  end

  before_save :reset_confirmed_at_if_email_changed
  after_save :claim_all_unclaimed_orders, :if => Proc.new{ |user| !confirmation_required? }
  before_create :set_confirmation_sent_at, :if => Proc.new{ |user| unclaimed_orders.empty? }

  def unclaimed_orders
    Order.where("orders.email = ? AND orders.completed_at IS NOT NULL AND orders.user_id != ?", email, id)
  end

  # overrides User.anonymous! in spree_auth
  def self.anonymous!
    token = User.generate_token(:persistence_token)
    user = User.new(:email => <EMAIL>", :password => <PASSWORD>, :password_confirmation => <PASSWORD>, :persistence_token => token)
    user.confirm! if Spree::ClaimOrder::Config[:require_email_confirmation]
    user
  end

  def claim_all_unclaimed_orders
    unclaimed_orders.each do |order|
      order.assign_to_rightful_owner
    end  unless confirmation_required?
  end

  protected

  # overrides Devise::Modules::Confirmable#confirmation_required?
  def confirmation_required?
   User.devise_modules.include?(:confirmable) && !unclaimed_orders.empty? && !confirmed?
  end

  private

  def reset_confirmed_at_if_email_changed
    self.confirmed_at = nil if (!self.new_record? and self.changed.include?("email"))
  end

  def set_confirmation_sent_at
    self.confirmation_sent_at = Time.now
  end
end
{'fraction_non_alphanumeric': 0.09204061578774976, 'fraction_numerical': 0.0, 'mean_word_length': 4.850574712643678, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, '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': '4199580', 'n_tokens_mistral': 972, 'n_tokens_neox': 945, 'n_words': 213}