<commit_before>class User < DBI::Model( :users )

  def self.authenticate( credentials )
    return nil  if credentials.nil? || credentials.empty?

    if credentials[ :api_key ]
      User[ :api_key => credentials[ :api_key ] ]
    elsif credentials[ :openid ]
      User[ :openid => credentials[ :openid ] ]
    elsif credentials[ :password ]
      encrypted_password = Digest::SHA1.hexdigest( credentials[ :password ] )
      User[
        :username => credentials[ :username ],
        :encrypted_password => <PASSWORD>
      ]
    end
  end

  def self.register( username, password )
    encrypted_password = <PASSWORD>.<PASSWORD>( password )
    User.create( username: username, encrypted_password: <PASSWORD> )
  end

  def to_s
    username || openid
  end

  def tracked_sites
    if admin?
      sites = SubdomainAccess.all
    else
      sites = SubdomainAccess.where( user_id: self.id )
    end
    sites.sort { |x,y|
      ax = x.subdomain.to_s.split( '.' )
      ay = y.subdomain.to_s.split( '.' )
      i = -1
      while ax[ i ] && ay[ i ] && ax[ i ] == ay[ i ]
        i -= 1
      end
      if ax[ i ] && ay[ i ]
        ax[ i ] <=> ay[ i ]
      elsif ax[ i ]
        1
      else
        -1
      end
    }
  end

  def admin?
    admin
  end

  def can_access?( subdomain )
    !! SubdomainAccess[ user_id: self.id, subdomain_id: subdomain.id, challenge: nil ]
  end

end<commit_msg>Allow admins to access any subdomain.<commit_after>class User < DBI::Model( :users )

  def self.authenticate( credentials )
    return nil  if credentials.nil? || credentials.empty?

    if credentials[ :api_key ]
      User[ :api_key => credentials[ :api_key ] ]
    elsif credentials[ :openid ]
      User[ :openid => credentials[ :openid ] ]
    elsif credentials[ :password ]
      encrypted_password = <PASSWORD>::SHA1.hexdigest( credentials[ :password ] )
      User[
        :username => credentials[ :username ],
        :encrypted_password => <PASSWORD>
      ]
    end
  end

  def self.register( username, password )
    encrypted_password = <PASSWORD>( password )
    User.create( username: username, encrypted_password: <PASSWORD> )
  end

  def to_s
    username || openid
  end

  def tracked_sites
    if admin?
      sites = SubdomainAccess.all
    else
      sites = SubdomainAccess.where( user_id: self.id )
    end
    sites.sort { |x,y|
      ax = x.subdomain.to_s.split( '.' )
      ay = y.subdomain.to_s.split( '.' )
      i = -1
      while ax[ i ] && ay[ i ] && ax[ i ] == ay[ i ]
        i -= 1
      end
      if ax[ i ] && ay[ i ]
        ax[ i ] <=> ay[ i ]
      elsif ax[ i ]
        1
      else
        -1
      end
    }
  end

  def admin?
    admin
  end

  def can_access?( subdomain )
    admin? || !! SubdomainAccess[ user_id: self.id, subdomain_id: subdomain.id, challenge: nil ]
  end

end
{'fraction_non_alphanumeric': 0.12098765432098765, 'fraction_numerical': 0.003527336860670194, 'mean_word_length': 2.200902934537246, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '565109', 'n_tokens_mistral': 956, 'n_tokens_neox': 931, 'n_words': 253}