summaryrefslogblamecommitdiffstats
path: root/lib/registration.rb
blob: 6afe8b6a2efc823cf8adb3e7f472210eba3f3279 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                           

              
                                               




                                                                      
                                                                                           
 
                                                                 

                                                                                                    
               

                          
   
 
                                    
                         


                      



                                
                              
                                                                                      
   
require_relative 'band'
require_relative 'pdf_form'
require 'mail'

def send_registration_emails_for(band, pdf_url)
  mail = Mail.new
  mail.charset = 'UTF-8'
  mail.to = 'haraldei@anduin.net'
  mail.from = @band.contact.email
  mail.subject = "Registrering av band #{@band.name} til Norsk Urskog"
  mail.body = erb :registration_email, :layout => false, :locals => { :pdf_url => pdf_url }

  if settings.environment != :test && settings.respond_to?(:smtp)
    mail.delivery_method :smtp, :address => settings.smtp['address'], :port => settings.smtp['port']
  end
  mail.deliver!
rescue Net::SMTPError => e
  band.errors << e.message
end

def generate_pdf_for(band, filename)
  pdf = PDFForm.new(band)
  pdf.render(filename)
end

def sanitize(s)
  s.gsub(/[ ,.:!^'*\/\\]+/, '-')
end

def create_pdf_file_name(band)
  filename = "#{Date.today.iso8601}-#{sanitize(band.name)}-#{sanitize(band.city)}.pdf"
end