# Band registration form for Norsk Urskog Metal Sampler # Copyright (C) 2015-2018 Harald Eilersen # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . require_relative 'band' require_relative 'pdf_form' require 'date' require 'mail' def send_registration_emails_for(band, pdf_url) mail = Mail.new mail.charset = 'UTF-8' mail.to = settings.contact_email 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) # Since the sinatra/indifferent_hash implementation that holds # the settings converts all keys to strings, and the mail gem # expects the keys as symbols, we need to create a new hash # with the correct keys. smtp_settings = Hash[settings.smtp.map { |e| [e[0].to_sym, e[1]] }] logger.debug "smtp settings: #{smtp_settings.inspect}" mail.delivery_method :smtp, smtp_settings 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 def parse_date(str) Date.parse(str) rescue TypeError => e $stderr << "Invalid date specified: " << str raise end def accept_registrations(settings) start_date = parse_date(settings.accept_registrations[:start]) end_date = parse_date(settings.accept_registrations[:stop]) start_date <= Date.today && end_date > Date.today end