ballalama3_app/app/controllers/public/registrants_controller.rb
Nicolas Bally 1a045e278a suite
2017-01-05 11:20:16 +01:00

50 lines
1.2 KiB
Ruby

# -*- encoding : utf-8 -*-
class Public::RegistrantsController < ApplicationController
layout "public"
def create
@registrant = Registrant.new(params.require(:registrant).permit!)
test = Registrant.find_by_email(@registrant.email)
if test
@registrant = test
General.confirm_email(@registrant).deliver
else
if @registrant.save
General.confirm_email(@registrant).deliver
else
render :action => :new
end
end
end
def edit
@registrant = Registrant.find_by_token(params[:id])
if @registrant
@registrant.destroy
redirect_to root_path, :notice => "L'adresse mail #{@registrant.email} à bien été supprimée de notre fichier."
else
redirect_to root_path, :notice => "Votre adresse mail ne figure pas dans notre fichier."
end
end
def email_validation
@registrant = Registrant.find_by_token(params[:id])
if @registrant
@registrant.enabled = true
@registrant.save
redirect_to root_path, :notice => "Merci ! Votre inscription est confirmée, vous recevrez désormais notre newsletter !"
else
redirect_to root_path, :notice => "Votre adresse mail ne figure pas dans notre fichier."
end
end
end