Skip to content

Instantly share code, notes, and snippets.

@manlycode
Created January 19, 2009 22:53
Show Gist options
  • Save manlycode/49223 to your computer and use it in GitHub Desktop.
Save manlycode/49223 to your computer and use it in GitHub Desktop.
#generate invite gets called from email_invite_with_template
def email_invite_with_template(template,params)
verification_mail = generate_invite
params[:login] ||= login.email
# create the attachment, if neede
if params[:include_optouts]
raise "request_report required parameter" unless params[:request_report]
raise "requests required parameter" unless params[:requests]
request_report = params.delete(:request_report)
request_report.compress
attachment = {
:content_type => request_report.mime_type,
:body => File.open(request_report.fname) { |f| f.read },
:filename => request_report.fname.gsub(/^.*\//,'')
}
end
verification_mail.send_mail ACTIVATE_URL,
params.merge(:queue => :email, :sender => SENDER, :template => template, :attachment => attachment, :merchant => self)
increment!(:invite_count)
# add a note to each catalog
catalogs.each do |catalog|
catalog.update_attribute(:note, catalog.note.to_s + "\n\nEmailed invite #{Time.now.to_date.to_s}")
end
end
#generate_invite creates an account if one doesn't exist, then it tries to find the first Verification Mail that was sent to this email addaress
def generate_invite
unless self.account
self.create_account
end
VerificationMail.find(:first,:conditions => {:email_sent_to => login.email}) || login.build_verification_mail
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment