<commit_before>require 'digest/sha1'
require 'acts_as_contributor'

class User < ActiveRecord::Base
  
  acts_as_contributor
  # TODO uncomment the following line when SOPs are implemented
  # has_many :sops, :as => :contributor
  
  belongs_to :person
  #validates_associated :person
  
  #restful_authentication plugin generated code ...
  # Virtual attribute for the unencrypted password
  attr_accessor :password

  #validates_presence_of     :login, :email - removed requirement on email
  #validates_length_of       :email,    :within => 3..100
  
  validates_presence_of     :login
  validates_presence_of     :password,                   :if => :password_required?
  validates_presence_of     :password_confirmation,      :if => :password_required?
  validates_length_of       :password, :within => 4..40, :if => :password_required?
  validates_confirmation_of :password,                   :if => :password_required?
  validates_length_of       :login,    :within => 3..40
  
  validates_uniqueness_of   :login, :case_sensitive => false
  before_save :encrypt_password
  before_create :make_activation_code 
  # prevents a user from submitting a crafted form that bypasses activation
  # anything else you want your user to change should be added here.
  attr_accessible :login, :email, :password, :password_confirmation
  
  has_many :favourites
  has_many :favourite_groups, :dependent => :destroy
  
  # can't destroy the assets, because these might be valuable even in the absence of the parent project
  has_many :assets, :as => :contributor, :dependent => :nullify

  named_scope :not_activated,:conditions=>['activation_code IS NOT NULL']
  named_scope :without_profile,:conditions=>['person_id IS NULL']
  named_scope :admins,:conditions=>['is_admin = true'],:include=>:person

  # Activates the user in the database.
  def activate
    @activated = true
    self.activated_at = Time.now.utc
    self.activation_code = nil
    save(false)
  end

  def active?
    # the existence of an activation code means they have not activated yet
    activation_code.nil?
  end

  # Authenticates a user by their login name and unencrypted password.  Returns the user or nil.
  def self.authenticate(login, password)<commit_msg>fixed admins named_scope for sqlite3 - therefore fixing the cruise control tests<commit_after>require 'digest/sha1'
require 'acts_as_contributor'

class User < ActiveRecord::Base
  
  acts_as_contributor
  # TODO uncomment the following line when SOPs are implemented
  # has_many :sops, :as => :contributor
  
  belongs_to :person
  #validates_associated :person
  
  #restful_authentication plugin generated code ...
  # Virtual attribute for the unencrypted password
  attr_accessor :password

  #validates_presence_of     :login, :email - removed requirement on email
  #validates_length_of       :email,    :within => 3..100
  
  validates_presence_of     :login
  validates_presence_of     :password,                   :if => :password_required?
  validates_presence_of     :password_confirmation,      :if => :password_required?
  validates_length_of       :password, :within => 4..40, :if => :password_required?
  validates_confirmation_of :password,                   :if => :password_required?
  validates_length_of       :login,    :within => 3..40
  
  validates_uniqueness_of   :login, :case_sensitive => false
  before_save :encrypt_password
  before_create :make_activation_code 
  # prevents a user from submitting a crafted form that bypasses activation
  # anything else you want your user to change should be added here.
  attr_accessible :login, :email, :password, :password_confirmation
  
  has_many :favourites
  has_many :favourite_groups, :dependent => :destroy
  
  # can't destroy the assets, because these might be valuable even in the absence of the parent project
  has_many :assets, :as => :contributor, :dependent => :nullify

  named_scope :not_activated,:conditions=>['activation_code IS NOT NULL']
  named_scope :without_profile,:conditions=>['person_id IS NULL']
  named_scope :admins,:conditions=>['is_admin = ?',true],:include=>:person

  # Activates the user in the database.
  def activate
    @activated = true
    self.activated_at = Time.now.utc
    self.activation_code = nil
    save(false)
  end

  def active?
    # the existence of an activation code means they have not activated yet
    activation_code.nil?
  end

  # Authenticates a user by their login name and unencrypted password.  Returns the user or nil.
  def self.authenticate(login, password)
{'fraction_non_alphanumeric': 0.07872105843439912, 'fraction_numerical': 0.005071664829106946, 'mean_word_length': 3.914409534127844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4181487', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1312, 'n_words': 407}