Skip to content
Extraits de code Groupes Projets
user.rb 2,36 ko
Newer Older
  • Learn to ignore specific revisions
  • maxwell's avatar
    maxwell a validé
    class User < Person
    
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable
    
    maxwell's avatar
    maxwell a validé
             
    
      #before_create :assign_key
    
      validates_presence_of :profile
      
      before_validation :do_bad_things
    
      def comment(text, options = {})
    
        raise "must comment on something!" unless options[:on]
    
    maxwell's avatar
    maxwell a validé
        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
    
    maxwell's avatar
    maxwell a validé
          else
            c.push_to([c.post.person])
          end
          true
        end
        false
    
    
      ######### Friend Requesting
      def send_friend_request_to(friend_url)
    
        unless Person.where(:url => friend_url).first
          p = Request.instantiate(:to => friend_url, :from => self)
          if p.save
            p.push_to_url friend_url
            p
          end
    
    maxwell's avatar
    maxwell a validé
      end 
    
    
      def accept_friend_request(friend_request_id)
        request = Request.where(:id => friend_request_id).first
        request.activate_friend
        request.person = self
    
    maxwell's avatar
    maxwell a validé
        request.destination_url = request.callback_url
    
        request.push_to_url(request.callback_url)
    
      def ignore_friend_request(friend_request_id)
        request = Request.where(:id => friend_request_id).first
        person = request.person
        person.destroy unless person.active
        request.destroy
      end
    
    
    maxwell's avatar
    maxwell a validé
        if Request.where(:callback_url => friend_request.callback_url).first
          friend_request.activate_friend
    
    maxwell's avatar
    maxwell a validé
      def mine?(post)
        self == post.person
      end
    
     
      def do_bad_things
        self.password_confirmation = self.password
      end
      
      
    
      def assign_key
        keys = GPGME.list_keys(nil, true)
        if keys.empty?
    
    ilya's avatar
    ilya a validé
          #generate_key
    
        end
        self.key_fingerprint = GPGME.list_keys(nil, true).first.subkeys.first.fingerprint
      end
    
      def generate_key
    
    ilya's avatar
    ilya a validé
        puts "Generating key"
    
        ctx = GPGME::Ctx.new
        paramstring = "<GnupgKeyParms format=\"internal\">
    Key-Type: DSA
    Key-Length: 512
    Subkey-Type: ELG-E
    Subkey-Length: 512
    Name-Real: #{self.real_name}
    Name-Comment: #{self.url}
    Name-Email: #{self.email}
    Expire-Date: 0
    Passphrase: #{self.password}
    </GnupgKeyParms>"
        ctx.genkey(paramstring, nil, nil)
        
      end