Allow a user's email address to be marked invalid, and suppress most
[rails.git] / app / models / notifier.rb
1 class Notifier < ActionMailer::Base
2   def signup_confirm(user, token)
3     recipients user.email
4     from "webmaster@openstreetmap.org"
5     subject "[OpenStreetMap] Confirm your email address"
6     headers "Auto-Submitted" => "auto-generated"
7     body :url => url_for(:host => SERVER_URL,
8                          :controller => "user", :action => "confirm",
9                          :confirm_string => token.token)
10   end
11
12   def lost_password(user, token)
13     recipients user.email
14     from "webmaster@openstreetmap.org"
15     subject "[OpenStreetMap] Password reset request"
16     headers "Auto-Submitted" => "auto-generated"
17     body :url => url_for(:host => SERVER_URL,
18                          :controller => "user", :action => "reset_password",
19                          :email => user.email, :token => token.token)
20   end
21
22   def reset_password(user, pass)
23     recipients user.email
24     from "webmaster@openstreetmap.org"
25     subject "[OpenStreetMap] Password reset"
26     headers "Auto-Submitted" => "auto-generated"
27     body :pass => pass
28   end
29
30   def gpx_success(trace, possible_points)
31     recipients trace.user.email if trace.user.email_valid
32     from "webmaster@openstreetmap.org"
33     subject "[OpenStreetMap] GPX Import success"
34     headers "Auto-Submitted" => "auto-generated"
35     body :trace_name => trace.name,
36          :trace_points => trace.size,
37          :trace_description => trace.description,
38          :trace_tags => trace.tags,
39          :possible_points => possible_points
40   end
41
42   def gpx_failure(trace, error)
43     recipients trace.user.email if trace.user.email_valid
44     from "webmaster@openstreetmap.org"
45     subject "[OpenStreetMap] GPX Import failure"
46     headers "Auto-Submitted" => "auto-generated"
47     body :trace_name => trace.name,
48          :trace_description => trace.description,
49          :trace_tags => trace.tags,
50          :error => error
51   end
52   
53   def message_notification(message)
54     recipients message.recipient.email if message.recipient.email_valid
55     from "webmaster@openstreetmap.org"
56     subject "[OpenStreetMap] #{message.sender.display_name} sent you a new message"
57     headers "Auto-Submitted" => "auto-generated"
58     body :to_user => message.recipient.display_name,
59          :from_user => message.sender.display_name,
60          :body => message.body,
61          :subject => message.title,
62          :readurl => url_for(:host => SERVER_URL,
63                              :controller => "message", :action => "read",
64                              :message_id => message.id),
65          :replyurl => url_for(:host => SERVER_URL,
66                               :controller => "message", :action => "reply",
67                               :message_id => message.id)
68   end
69
70   def diary_comment_notification(comment)
71     recipients comment.diary_entry.user.email if comment.diary_entry.user.email_valid
72     from "webmaster@openstreetmap.org"
73     subject "[OpenStreetMap] #{comment.user.display_name} commented on your diary entry"
74     headers "Auto-Submitted" => "auto-generated"
75     body :to_user => comment.diary_entry.user.display_name,
76          :from_user => comment.user.display_name,
77          :body => comment.body,
78          :subject => comment.diary_entry.title,
79          :readurl => url_for(:host => SERVER_URL,
80                              :controller => "diary_entry",
81                              :action => "view",
82                              :display_name => comment.diary_entry.user.display_name,
83                              :id => comment.diary_entry.id,
84                              :anchor => "comment#{comment.id}"),
85          :commenturl => url_for(:host => SERVER_URL,
86                                 :controller => "diary_entry",
87                                 :action => "view",
88                                 :display_name => comment.diary_entry.user.display_name,
89                                 :id => comment.diary_entry.id,
90                                 :anchor => "newcomment"),
91          :replyurl => url_for(:host => SERVER_URL,
92                               :controller => "message",
93                               :action => "new",
94                               :user_id => comment.user.id,
95                               :title => "Re: #{comment.diary_entry.title}")
96   end
97
98   def friend_notification(friend)
99     befriender = User.find_by_id(friend.user_id)
100     befriendee = User.find_by_id(friend.friend_user_id)
101
102     recipients befriendee.email if  befriendee.email_valid
103     from "webmaster@openstreetmap.org"
104     subject "[OpenStreetMap] #{befriender.display_name} added you as a friend"
105     headers "Auto-Submitted" => "auto-generated"
106     body :user => befriender.display_name,
107          :userurl => url_for(:host => SERVER_URL,
108                              :controller => "user", :action => "view",
109                              :display_name => befriender.display_name)
110   end
111 end