summaryrefslogtreecommitdiffstats
path: root/registration.rb
blob: c6598d12a80e16fb62052395badf01c182aa3e94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'sinatra/base'
require 'sinatra/url_for'
require_relative 'lib/registration'

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

  get '/' do
    @errors = request['errors']
    @errors = @errors.split('|') if @errors
    erb :index
  end

  post '/submit' do
    if request.form_data?
      #p request['band']
      @band = Band.new(request['band'])
      if @band.valid?
        generate_pdf_for @band
        send_registration_emails_for @band
        erb :submitted
      else
        redirect to(url_for('/', :errors => @band.errors.join('|')))
      end
    end
  end

  run! if app_file == $0
end