<commit_before>class User < Person

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
         
  
  #before_create :assign_key
  validates_presence_of :profile
  
  before_validation :do_bad_things


  ######## Commenting  ########
  def comment(text, options = {})
    raise "must comment on something!" unless options[:on]
    c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
    if c.save
      if mine?(c.post)
        c.push_to(c.post.people_with_permissions)  # should return plucky query
      else
        c.push_to([c.post.person])
      end
      true
    end
    false
  end

  ######### Friend Requesting
  def send_friend_request_to(friend_url)
    p = Request.instantiate(:to => friend_url, :from => self)
    if p.save
      p.push_to_url friend_url
      p
    end
  end 

  
  def do_bad_things
    self.password_confirmation = <PASSWORD>
  end

  def accept_friend_request(friend_request_id)
    request = Request.where(:id => friend_request_id).first
    request.activate_friend
    request.person = self
    request.destination_url = request.callback_url
    request.push_to_url(request.callback_url)
    request.destroy
  end

  def receive_friend_request(friend_request)
    if Request.where(:callback_url => friend_request.callback_url).first
      friend_request.activate_friend
      friend_request.destroy
    else
      #does this actually save as the same id?
      friend_request.save
    end
  end
 

  def mine?(post)
    self == post.person
  end

  protected
  
  def assign_key
    keys = GPGME.list_keys(nil, true)
    if keys.empty?
      generate_key
    end
    self.key_fingerprint = GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
  end

  def generate_key
    puts "Generating key"
    ctx = GPGME::Ctx.new
    paramstring = "<GnupgKeyParms format=\"internal\">
Key-Type: DSA
Key-Length: 512<commit_msg>Use pregenerated keys<commit_after>class User < Person

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
         
  
  before_create :assign_key
  validates_presence_of :profile
  
  before_validation :do_bad_things


  ######## Commenting  ########
  def comment(text, options = {})
    raise "must comment on something!" unless options[:on]
    c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
    if c.save
      if mine?(c.post)
        c.push_to(c.post.people_with_permissions)  # should return plucky query
      else
        c.push_to([c.post.person])
      end
      true
    end
    false
  end

  ######### Friend Requesting
  def send_friend_request_to(friend_url)
    p = Request.instantiate(:to => friend_url, :from => self)
    if p.save
      p.push_to_url friend_url
      p
    end
  end 

  
  def do_bad_things
    self.password_confirmation = <PASSWORD>
  end

  def accept_friend_request(friend_request_id)
    request = Request.where(:id => friend_request_id).first
    request.activate_friend
    request.person = self
    request.destination_url = request.callback_url
    request.push_to_url(request.callback_url)
    request.destroy
  end

  def receive_friend_request(friend_request)
    if Request.where(:callback_url => friend_request.callback_url).first
      friend_request.activate_friend
      friend_request.destroy
    else
      #does this actually save as the same id?
      friend_request.save
    end
  end
 

  def mine?(post)
    self == post.person
  end

  protected
  
  def assign_key
    keys = GPGME.list_keys(nil, true)
    if keys.empty?
      #generate_key
    end
    self.key_fingerprint = GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
  end

  def generate_key
    puts "Generating key"
    ctx = GPGME::Ctx.new
    paramstring = "<GnupgKeyParms format=\"internal\">
Key-Type: DSA
Key-Length: 512
{'fraction_non_alphanumeric': 0.09733606557377049, 'fraction_numerical': 0.0015368852459016393, 'mean_word_length': 3.063475546305931, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2311552', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1249, 'n_words': 273}