Newer
Older
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
maxwell
a validé
validates_presence_of :profile
before_validation :do_bad_things
maxwell
a validé
######## Commenting ########
def comment(text, options = {})
maxwell
a validé
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)
danielvincent
a validé
c.push_to(c.post.people_with_permissions) # should return plucky query
else
c.push_to([c.post.person])
end
true
end
false
maxwell
a validé
######### 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
maxwell
a validé
end
maxwell
a validé
def accept_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
request.activate_friend
request.person = self
maxwell
a validé
request.destroy
end
def ignore_friend_request(friend_request_id)
person = request.person
person.destroy unless person.active
request.destroy
end
maxwell
a validé
def receive_friend_request(friend_request)
Rails.logger.info("receiving friend request #{friend_request.to_json}")
if Request.where(:callback_url => friend_request.callback_url).first
friend_request.activate_friend
maxwell
a validé
friend_request.destroy
else
friend_request.person.save
maxwell
a validé
friend_request.save
end
end
def unfriend(friend_id)
bad_friend = Person.first(:id => friend_id, :active => true)
if bad_friend
Retraction.for(self).push_to_url(bad_friend.url)
bad_friend.destroy
end
end
###Helpers############
def do_bad_things
self.password_confirmation = self.password
end
def self.owner
User.first
end
self.key_fingerprint = GPGME.list_keys(real_name, true).first.subkeys.first.fingerprint
end
def generate_key
puts paramstring
ctx.genkey(paramstring, nil, nil)
end
def 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
</GnupgKeyParms>"