<commit_before>class User < ActiveRecord::Base
  has_many :submissions, dependent: :destroy
  has_many :comments, dependent: :destroy
  validates :username, presence: true, uniqueness: {case_sensitive: false}
  validates :first_name, presence: true
  validates :last_name, presence: true
  validates :email, presence: true

  attr_accessor :display_name

  def self.find_or_create(username)
    #Find the user by their username
    user = User.find_by(username: username.downcase)
    
    #If the user doesn't exist make a new user.  Split their username to get their first name and last name
    if user.nil?
      user = User.new
      user.username = username.downcase
      user.first_name,user.last_name = user.username.split('.')
      user.username = "#{user.first_name}#{user.last_name}".downcase if user.first_name.length==1
    end
    
    user.save
    return user
  end
  
  def validate_against_ad(password)
    #Do authentication against the AD.
    return false if password.blank?
    unless Rails.env.production?
      self.first_name,self.last_name = self.username.downcase.split(".") if self.first_name.blank? or self.last_name.blank?
      self.email = "#{self.<EMAIL>" if self.email.blank?
      return true
    end
    
    ldap = Net::LDAP.new :host => '10.238.242.32',
    :port => 389,
    :auth => {
      :method => :simple,
      :username => "ORASI\\#{self.username}",
      :password => password
    }
    validated = ldap.bind
    if validated and (self.first_name.blank? or self.last_name.blank?)
    
      filter = Net::LDAP::Filter.eq("samaccountname", self.username)
      treebase = "dc=orasi, dc=com"<commit_msg>Quick fixes for email.<commit_after>class User < ActiveRecord::Base
  has_many :submissions, dependent: :destroy
  has_many :comments, dependent: :destroy
  validates :username, presence: true, uniqueness: {case_sensitive: false}
  validates :first_name, presence: true
  validates :last_name, presence: true
  validates :email, presence: true

  attr_accessor :display_name

  def self.find_or_create(username)
    #Find the user by their username
    user = User.find_by(username: username.downcase)
    
    #If the user doesn't exist make a new user.  Split their username to get their first name and last name
    if user.nil?
      user = User.new
      user.username = username.downcase
      user.first_name,user.last_name = user.username.split('.')
      user.username = "#{user.first_name}#{user.last_name}".downcase if user.first_name.length==1
    end
    
    user.save
    return user
  end
  
  def validate_against_ad(password)
    #Do authentication against the AD.
    return false if password.blank?
    unless Rails.env.production?
      self.first_name,self.last_name = self.username.downcase.split(".") if self.first_name.blank? or self.last_name.blank?
      self.email = <EMAIL>" if self.email.blank?
      return true
    end
    
    ldap = Net::LDAP.new :host => '10.238.242.32',
    :port => 389,
    :auth => {
      :method => :simple,
      :username => "ORASI\\#{self.username}",
      :password => password
    }
    validated = ldap.bind
    if validated and (self.first_name.blank? or self.last_name.blank? or self.email.blank?)
    
      filter = Net::LDAP::Filter.eq("samaccountname", self.username)
      treebase = "dc=orasi, dc=com"
{'fraction_non_alphanumeric': 0.11432009626955475, 'fraction_numerical': 0.00842358604091456, 'mean_word_length': 3.219543147208122, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '871935', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1045, 'n_words': 270}