<commit_before>require 'digest/sha1'
require 'net/pop'
require 'net/https'
require 'net/http'
require 'json'

class User < ActiveRecord::Base

  has_and_belongs_to_many :roles

  #has_and_belongs_to_many :groups
  has_many :groups_users, class_name: GroupUser
  has_many :groups, :through => :groups_users

  has_many :test_requests, -> {order(submitted_at: DESC)}

  has_many :messages, -> { order(created_at: DESC) },
           :class_name => "Message",
           :foreign_key => "sender_id"

  has_many :replied_messages, -> { order(created_at: DESC) },
           :class_name => "Message",
           :foreign_key => "receiver_id"

  has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy

  belongs_to :site
  belongs_to :country

  has_and_belongs_to_many :contests, -> { order(:name); uniq}

  scope :activated_users, -> {where activated: true}

  validates_presence_of :login
  validates_uniqueness_of :login
  validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/
  validates_length_of :login, :within => 3..30

  validates_presence_of :full_name
  validates_length_of :full_name, :minimum => 1
  
  validates_presence_of :password, :if => :password_required?
  validates_length_of :password, :within => 4..20, :if => :password_required?
  validates_confirmation_of :password, :if => :password_required?

  validates_format_of :email, 
                      :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, 
                      :if => :email_validation?
  validate :uniqueness_of_email_from_activated_users, 
           :if => :email_validation?<commit_msg>increases max password length to 50<commit_after>require 'digest/sha1'
require 'net/pop'
require 'net/https'
require 'net/http'
require 'json'

class User < ActiveRecord::Base

  has_and_belongs_to_many :roles

  #has_and_belongs_to_many :groups
  has_many :groups_users, class_name: GroupUser
  has_many :groups, :through => :groups_users

  has_many :test_requests, -> {order(submitted_at: DESC)}

  has_many :messages, -> { order(created_at: DESC) },
           :class_name => "Message",
           :foreign_key => "sender_id"

  has_many :replied_messages, -> { order(created_at: DESC) },
           :class_name => "Message",
           :foreign_key => "receiver_id"

  has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy

  belongs_to :site
  belongs_to :country

  has_and_belongs_to_many :contests, -> { order(:name); uniq}

  scope :activated_users, -> {where activated: true}

  validates_presence_of :login
  validates_uniqueness_of :login
  validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/
  validates_length_of :login, :within => 3..30

  validates_presence_of :full_name
  validates_length_of :full_name, :minimum => 1
  
  validates_presence_of :password, :if => :password_required?
  validates_length_of :password, :within => 4..50, :if => :password_required?
  validates_confirmation_of :password, :if => :password_required?

  validates_format_of :email, 
                      :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, 
                      :if => :email_validation?
  validate :uniqueness_of_email_from_activated_users, 
           :if => :email_validation?
{'fraction_non_alphanumeric': 0.13852813852813853, 'fraction_numerical': 0.008658008658008658, 'mean_word_length': 3.871987951807229, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '1156047', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1130, 'n_words': 216}