summaryrefslogblamecommitdiffstats
path: root/registration.rb
blob: ea7fdf35e54775cd181a5c8c85938987476c4105 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                             
                    
                      
                         
                             
                  
                                   

                                     
                              

                               
 
                    
                            
 
                                                    
 
                                       
                                                                              
     
 
            


                                       

     



                                

                         
                                       
                     
                                                                     
                                                                            
                                                                     


                     

                      
                  
         


       

                        
# Band registration form for Norsk Urskog Metal Sampler
# Copyright (C) 2015-2018  Harald Eilersen <haraldei@anduin.net>
#
# 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 <http://www.gnu.org/licenses/>.

require 'mustermann'
require 'sinatra/base'
require 'sinatra/url_for'
require 'sinatra/config_file'
require 'tilt/erb'
require_relative 'lib/registration'

class RegistrationApp < Sinatra::Base
  register Sinatra::ConfigFile
  helpers Sinatra::UrlForHelper
  include ERB::Util

  set :logging, true
  set :pattern, type: :regex

  config_file File.join(settings.root, 'config.yml')

  before Mustermann.new('/|/submit') do
    redirect to('/registrations_closed') unless accept_registrations(settings)
  end

  get '/' do
    @band = Band.new
    3.times { @band.songs << Song.new }
    erb :index
  end

  get '/registrations_closed' do
    erb :registration_closed
  end

  post '/submit' do
    if request.form_data?
      @band = Band.new(request['band'])
      if @band.valid?
        pdf_file = File.join("/uploads", create_pdf_file_name(@band))
        generate_pdf_for(@band, File.join(settings.public_folder, pdf_file))
        send_registration_emails_for(@band, url_for(pdf_file, :full))
      end

      if @band.valid?
        erb :submitted
      else
        erb :index
      end
    end
  end

  run! if app_file == $0
end