diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb
index 56f0f3555..8ce7995b4 100644
--- a/app/mailers/notifier.rb
+++ b/app/mailers/notifier.rb
@@ -4,11 +4,7 @@ class Notifier < ActionMailer::Base
def new_request(recipient, sender)
@receiver = recipient
@sender = sender
- mail(:to => recipient.email) do |format|
- format.text { render :text => "This is text!" }
- format.html { render :text => "
#{@receiver.person.profile.first_name}This is HTML
" }
- end
+ mail(:to => "#{recipient.real_name} <#{recipient.email}>",
+ :subject => "new friend request from #{@sender.inspect}")
end
-
-
end
diff --git a/app/views/notifier/new_request.html.haml b/app/views/notifier/new_request.html.haml
index daa54c0eb..54cee3ddd 100644
--- a/app/views/notifier/new_request.html.haml
+++ b/app/views/notifier/new_request.html.haml
@@ -46,16 +46,13 @@
= image_tag '/images/diaspora_white.png'
#container
%p
- Hello #{@receiver.first_name}!
+ Hello #{@receiver.profile.first_name}!
%p
- #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " (#{@resource.inviters.first.diaspora_handle})" + " has") : (@resource.inviters.map{|inv| inv.real_name + " (#{inv.diaspora_handle})"}.join(",") + " have")} invited you to join Diaspora at #{root_url}, you can accept it through the link below.
- - @resource.inviters.each do |inv|
- - if @resource.invite_messages[inv.id.to_s]
- = "#{inv.real_name}:"
- = @resource.invite_messages[inv.id.to_s]
- %p
- %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text"
- %p.small
- If you don't want to accept the invitation, please ignore this email.
- %br/
- Your account won't be created until you access the link above and sign up.
+ = "#{@sender.real_name} (#{@sender.diaspora_handle})"
+ just sent you a friend request on Diaspora*
+ You should really think about checking it out.
+
+ = link_to "sign in here", new_user_session_path
+
+ love,
+ the diaspora email robot
diff --git a/app/views/notifier/new_request.text.haml b/app/views/notifier/new_request.text.haml
new file mode 100644
index 000000000..1c1505f74
--- /dev/null
+++ b/app/views/notifier/new_request.text.haml
@@ -0,0 +1,9 @@
+= "hey #{@receiver.profile.first_name},"
+= "#{@sender.real_name} (#{@sender.diaspora_handle})"
+just sent you a friend request on Diaspora*
+You should really think about checking it out.
+
+= "sign in here: #{new_user_session_path}"
+
+love,
+the diaspora email robot
diff --git a/config/initializers/setup_mail.rb b/config/initializers/setup_mail.rb
new file mode 100644
index 000000000..e94ea5133
--- /dev/null
+++ b/config/initializers/setup_mail.rb
@@ -0,0 +1 @@
+ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
diff --git a/lib/development_mail_interceptor.rb b/lib/development_mail_interceptor.rb
new file mode 100644
index 000000000..efc89596f
--- /dev/null
+++ b/lib/development_mail_interceptor.rb
@@ -0,0 +1,7 @@
+class DevelopmentMailInterceptor
+ def self.delivering_email(message)
+ message.subject = "[#{message.to}] #{message.subject}"
+ message.to = "email@joindiaspora.com"
+ end
+end
+
diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb
index 570ce3544..c7809b39d 100644
--- a/lib/diaspora/user/friending.rb
+++ b/lib/diaspora/user/friending.rb
@@ -74,7 +74,7 @@ module Diaspora
else
self.pending_requests << friend_request
self.save
- Notifier.new_request(self, friend_request.person)
+ Notifier.new_request(self, friend_request.person).deliver
Rails.logger.info("#{self.real_name} has received a friend request")
friend_request.save
end
diff --git a/spec/factories.rb b/spec/factories.rb
index c66fa4f86..8d0b76aee 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -8,14 +8,15 @@
#This inclsion, because gpg-agent(not needed) is never run and hence never sets any env. variables on a MAC
Factory.define :profile do |p|
- p.first_name "Robert"
- p.last_name "Grimm"
+ p.sequence(:first_name){|n| "Robert#{n}"}
+ p.sequence(:last_name){|n| "Grimm#{n}"}
end
+
Factory.define :person do |p|
p.sequence(:diaspora_handle) {|n| "bob-person-#{n}@aol.com"}
p.sequence(:url) {|n| "http://google-#{n}.com/"}
- p.profile Factory.create(:profile)
+ p.profile Factory.create(:profile, :first_name => "eugene", :last_name => "weinstien")
p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
end
@@ -32,7 +33,7 @@ Factory.define :user do |u|
u.password_confirmation "bluepin7"
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
u.after_build do |user|
- user.person = Factory.build(:person, :owner_id => user._id,
+ user.person = Factory.build(:person, :profile => Factory.create(:profile), :owner_id => user._id,
:serialized_public_key => user.encryption_key.public_key.export,
:diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
end
diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb
index 97316890d..394733cea 100644
--- a/spec/mailers/notifier_spec.rb
+++ b/spec/mailers/notifier_spec.rb
@@ -3,9 +3,9 @@ require 'spec_helper'
describe Notifier do
- let(:user) {Factory.create :user}
- let(:person) {Factory.create :person}
- let(:request_mail) {Notifier.new_request(user, person)}
+ let!(:user) {Factory.create :user}
+ let!(:person) {Factory.create :person}
+ let!(:request_mail) {Notifier.new_request(user, person)}
describe "#new_request" do
it 'goes to the right person' do
@@ -13,7 +13,12 @@ describe Notifier do
end
it 'has the receivers name in the body' do
- request_mail.body.encoded.includes?(user.first_name).should be true
+ request_mail.body.encoded.include?(user.person.profile.first_name).should be true
+ end
+
+
+ it 'has the name of person sending the request' do
+ request_mail.body.encoded.include?(person.real_name).should be true
end
end
end
diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb
index 67235f447..36a586647 100644
--- a/spec/models/user/attack_vectors_spec.rb
+++ b/spec/models/user/attack_vectors_spec.rb
@@ -4,7 +4,7 @@
require 'spec_helper'
-describe User do
+describe "attack vectors" do
let(:user) { Factory(:user) }
let(:aspect) { user.aspect(:name => 'heroes') }
@@ -73,10 +73,11 @@ describe User do
profile.first_name = "Not BOB"
user2.reload
- user2.profile.first_name.should == "Robert"
+
+ first_name = user2.profile.first_name
proc{user.receive_salmon(user3.salmon(profile).xml_for(user.person))}.should raise_error /Malicious Post/
user2.reload
- user2.profile.first_name.should == "Robert"
+ user2.profile.first_name.should == first_name
end
it 'should not overwrite another persons profile through comment' do