<commit_before>class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: { medium: "300x300>", thumb: "100x100>#", head: "32x32#" },
    default_url: 'standard_:style.png'
  
  attr_accessible :user_phenotypes_attributes, :variation, :characteristic,
    :name, :password_confirmation, :password, :email, :description, :homepages,
    :homepages_attributes,:avatar, :sex, :yearofbirth,
    :phenotype_creation_counter, :phenotype_additional_counter,:delete_avatar,
    :message_on_message, :message_on_phenotype_comment_reply,
    :message_on_snp_comment_reply, :message_on_new_phenotype,
    :message_on_newsletter, :has_sequence, :sequence_link

  before_validation :clear_avatar
  
  validates_attachment_size :avatar, less_than: 1.megabyte
  validates_attachment_content_type :avatar,
    content_type: ['image/jpeg', 'image/png', 'image/gif']
  # call on authlogic
  acts_as_authentic do |c| 
      # replace SHA512 by bcrypt
      c.transition_from_crypto_providers = Authlogic::CryptoProviders::Sha512
      c.crypto_provider = Authlogic::CryptoProviders::BCrypt
  end
  #after_create :make_standard_phenotypes

  # dependent so stuff gets destroyed on delete
  has_many :user_phenotypes, :dependent => :destroy
  has_many :phenotypes, :through => :user_phenotypes
  has_many :user_picture_phenotypes, :dependent => :destroy
  has_many :picture_phenotypes, :through => :user_picture_phenotypes
  has_many :genotypes, :dependent => :destroy
  has_many :user_snps, through: :genotypes
  has_many :snps, through: :user_snps
  has_many :homepages, dependent: :destroy
  has_many :messages, dependent: :destroy
  has_many :user_achievements, dependent: :destroy
  has_many :achievements, through: :user_achievements
  has_many :snp_comments # these shouldn't be deleted, but orphaned
  has_many :phenotype_comments
  has_many :picture_phenotype_comments
  has_one :fitbit_profile

  # needed to edit several user_phenotypes at once, add and delete, and not empty
  accepts_nested_attributes_for :homepages, allow_destroy: true
  accepts_nested_attributes_for :user_phenotypes, allow_destroy: true

  searchable do
    text :description, :name
  end

  def deliver_password_reset_instructions!
    reset_perishable_token!
    UserMailer.password_reset_instructions(self).deliver
  end

  def phenotype_length
     # tiny workaround for user-index
     phenotypes.length
  end<commit_msg>Prevents Solr reindexing of user on login. Users can now log in even if Solr is off. See http://stackoverflow.com/questions/6040493/sunspot-index-only-when-searchable-fields-change<commit_after>class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: { medium: "300x300>", thumb: "100x100>#", head: "32x32#" },
    default_url: 'standard_:style.png'
  
  attr_accessible :user_phenotypes_attributes, :variation, :characteristic,
    :name, :password_confirmation, :password, :email, :description, :homepages,
    :homepages_attributes,:avatar, :sex, :yearofbirth,
    :phenotype_creation_counter, :phenotype_additional_counter,:delete_avatar,
    :message_on_message, :message_on_phenotype_comment_reply,
    :message_on_snp_comment_reply, :message_on_new_phenotype,
    :message_on_newsletter, :has_sequence, :sequence_link

  before_validation :clear_avatar
  
  validates_attachment_size :avatar, less_than: 1.megabyte
  validates_attachment_content_type :avatar,
    content_type: ['image/jpeg', 'image/png', 'image/gif']
  # call on authlogic
  acts_as_authentic do |c| 
      # replace SHA512 by bcrypt
      c.transition_from_crypto_providers = Authlogic::CryptoProviders::Sha512
      c.crypto_provider = Authlogic::CryptoProviders::BCrypt
  end
  #after_create :make_standard_phenotypes

  # dependent so stuff gets destroyed on delete
  has_many :user_phenotypes, :dependent => :destroy
  has_many :phenotypes, :through => :user_phenotypes
  has_many :user_picture_phenotypes, :dependent => :destroy
  has_many :picture_phenotypes, :through => :user_picture_phenotypes
  has_many :genotypes, :dependent => :destroy
  has_many :user_snps, through: :genotypes
  has_many :snps, through: :user_snps
  has_many :homepages, dependent: :destroy
  has_many :messages, dependent: :destroy
  has_many :user_achievements, dependent: :destroy
  has_many :achievements, through: :user_achievements
  has_many :snp_comments # these shouldn't be deleted, but orphaned
  has_many :phenotype_comments
  has_many :picture_phenotype_comments
  has_one :fitbit_profile

  # needed to edit several user_phenotypes at once, add and delete, and not empty
  accepts_nested_attributes_for :homepages, allow_destroy: true
  accepts_nested_attributes_for :user_phenotypes, allow_destroy: true

  # The following should turn off auto-reindex of user on login
  searchable :ignore_attribute_changes_of => [:persistence_token, :perishable_token, :updated_at] do
    text :description, :name
  end

  def deliver_password_reset_instructions!
    reset_perishable_token!
    UserMailer.password_reset_instructions(self).deliver
  end

  def phenotype_length
     # tiny workaround for user-index
     phenotypes.length
  end
{'fraction_non_alphanumeric': 0.08297540023428349, 'fraction_numerical': 0.010347520499804764, 'mean_word_length': 5.758575197889182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '3781345', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1616, 'n_words': 371}