Make open source
This commit is contained in:
9
app/controllers/application_controller.rb
Normal file
9
app/controllers/application_controller.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
if ENV['BASIC_AUTH_NAME'] && ENV['BASIC_AUTH_PASSWORD']
|
||||
http_basic_authenticate_with \
|
||||
name: ENV['BASIC_AUTH_NAME'],
|
||||
password: ENV['BASIC_AUTH_PASSWORD']
|
||||
end
|
||||
end
|
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
75
app/controllers/guests_controller.rb
Normal file
75
app/controllers/guests_controller.rb
Normal file
@ -0,0 +1,75 @@
|
||||
class GuestsController < ApplicationController
|
||||
def new
|
||||
respond_to :html
|
||||
|
||||
@guest = Guest.new
|
||||
end
|
||||
|
||||
def create
|
||||
respond_to :html
|
||||
|
||||
@guest = Guest.new(guest_params)
|
||||
unless ENV['RECAPTCHA_SECRET_KEY'].blank? || verify_recaptcha(model: @guest)
|
||||
render :new
|
||||
return
|
||||
end
|
||||
|
||||
if @guest.save
|
||||
redirect_to guest_path(@guest)
|
||||
else
|
||||
existing_guest = Guest.find_by(email: guest_params[:email])
|
||||
if existing_guest
|
||||
@guest = existing_guest
|
||||
GuestMailer.welcome_back_email(@guest).deliver_now
|
||||
render :new_exists
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to :html
|
||||
|
||||
@guest = Guest.find_by_id_token(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@guest = Guest.find_by_id_token(params[:id])
|
||||
|
||||
if @guest.update(guest_params)
|
||||
if @guest.attending?
|
||||
redirect_to guest_plus_ones_path(@guest)
|
||||
else
|
||||
redirect_to confirm_guest_path(@guest)
|
||||
end
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
def confirm
|
||||
respond_to :html
|
||||
|
||||
@guest = Guest.find_by_id_token(params[:id])
|
||||
end
|
||||
|
||||
def complete
|
||||
respond_to :html
|
||||
|
||||
@guest = Guest.find_by_id_token(params[:id])
|
||||
Guest.transaction do
|
||||
@guest.update!(guest_params)
|
||||
@guest.touch :confirmed_at
|
||||
end
|
||||
GuestMailer.confirmation_email(@guest).deliver_now
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def guest_params
|
||||
params.require(:guest).permit(
|
||||
:email, :first_name, :last_name, :attending, :diet, :songs, :notes
|
||||
)
|
||||
end
|
||||
end
|
53
app/controllers/plus_ones_controller.rb
Normal file
53
app/controllers/plus_ones_controller.rb
Normal file
@ -0,0 +1,53 @@
|
||||
class PlusOnesController < ApplicationController
|
||||
before_action do
|
||||
@guest = Guest.find_by_id_token(params[:guest_id])
|
||||
end
|
||||
|
||||
def new
|
||||
respond_to :html
|
||||
@plus_one = @guest.plus_ones.new
|
||||
end
|
||||
|
||||
def create
|
||||
respond_to :html
|
||||
@plus_one = @guest.plus_ones.new(plus_one_params)
|
||||
if @plus_one.save
|
||||
redirect_to guest_plus_ones_path(@guest)
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
respond_to :html
|
||||
@plus_ones = @guest.plus_ones.order(:first_name, :last_name)
|
||||
end
|
||||
|
||||
def edit
|
||||
@plus_one = @guest.plus_ones.find(params[:id])
|
||||
respond_to :html
|
||||
end
|
||||
|
||||
def update
|
||||
@plus_one = @guest.plus_ones.find(params[:id])
|
||||
|
||||
if @plus_one.update(plus_one_params)
|
||||
redirect_to guest_plus_ones_path(@guest)
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
respond_to :html
|
||||
@plus_one = @guest.plus_ones.find_by(id: params[:id])
|
||||
@plus_one.destroy if @plus_one
|
||||
redirect_to guest_plus_ones_path(@guest)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def plus_one_params
|
||||
params.require(:plus_one).permit(:first_name, :last_name, :diet, :child)
|
||||
end
|
||||
end
|
6
app/controllers/welcome_controller.rb
Normal file
6
app/controllers/welcome_controller.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class WelcomeController < ApplicationController
|
||||
def index
|
||||
@google_maps_url = 'https://goo.gl/maps/nBAxNAsmPSS2'
|
||||
@cool_earth_url = 'https://www.coolearth.org/'
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user