summaryrefslogtreecommitdiffstats
path: root/registration.rb
blob: 28883870e4dfdfa99f72fc911926f7b9d56951bc (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
31
32
33
34
35
36
37
38
39
require 'sinatra/base'
require 'sinatra/url_for'
require 'tilt/erb'
require_relative 'lib/registration'

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

  enable :sessions

  get '/' do
    @band = Band.new
    erb :index
  end

  get '/member/new/:num' do
    erb :member, :layout => false, :locals => { :member_number => params['num'] }
  end

  get '/song/new/:num' do
    erb :song, :layout => false, :locals => { :song_number => params['num'] }
  end

  post '/submit' do
    if request.form_data?
      @band = Band.new(request['band'])
      if @band.valid?
        generate_pdf_for @band
        send_registration_emails_for @band
        erb :submitted
      else
        erb :index
      end
    end
  end

  run! if app_file == $0
end