diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/track_mailer.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 30 |
2 files changed, 35 insertions, 3 deletions
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index f8bef4d61..85b1fedd8 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -26,6 +26,12 @@ class TrackMailer < ApplicationMailer @body = { :user => user, :email_about_things => email_about_things, :unsubscribe_url => unsubscribe_url } end + def contact_from_name_and_email + contact_name = MySociety::Config.get("TRACK_SENDER_NAME", 'Alaveteli') + contact_email = MySociety::Config.get("TRACK_SENDER_EMAIL", 'contact@localhost') + return "#{contact_name} <#{contact_email}>" + end + # Send email alerts for tracked things. Never more than one email # a day, nor about events which are more than a week old, nor # events about which emails have been sent within the last two @@ -40,6 +46,8 @@ class TrackMailer < ApplicationMailer return false end for user in users + next if !user.should_be_emailed? + email_about_things = [] track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ? and track_medium = ?", user.id, 'email_daily' ]) for track_thing in track_things diff --git a/app/models/user.rb b/app/models/user.rb index c3c3da6f7..e98d777b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,8 @@ # admin_level :string(255) default("none"), not null # ban_text :text default(""), not null # about_me :text default(""), not null +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null # # models/user.rb: @@ -350,15 +352,37 @@ class User < ActiveRecord::Base } end + def record_bounce(message) + self.email_bounced_at = Time.now + self.email_bounce_message = message + self.save! + end + + def should_be_emailed? + return (self.email_confirmed && self.email_bounced_at.nil?) + end + + ## Private instance methods private + def create_new_salt + self.salt = self.object_id.to_s + rand.to_s + end + + ## Class methods def User.encrypted_password(password, salt) string_to_hash = password + salt # XXX need to add a secret here too? Digest::SHA1.hexdigest(string_to_hash) end - - def create_new_salt - self.salt = self.object_id.to_s + rand.to_s + + def User.record_bounce_for_email(email, message) + user = User.find_user_by_email(email) + return false if user.nil? + + if user.email_bounced_at.nil? + user.record_bounce(message) + end + return true end end |