# frozen_string_literal: true module MrCommon module Registrations class ConfirmationsController < BaseController # Confirm a registration. def create find_registration if confirm_registration send_notification redirect_to @registration, notice: "Registration confirmed. Registrant will receive an email." else Rails.logger.debug(@registration.errors.full_messages) redirect_to @registration, alert: "Unable to confirm registration" end end # Revoke a registration's confirmation. def destroy find_registration if unconfirm_registration send_notification redirect_to @registration, notice: "Confirmation revoked. Registrant will receive an email." else Rails.logger.debug(@registration.errors.full_messages) redirect_to @registration, alert: "Unable to revoke confirmation" end end private def find_registration @registration = MrCommon::Registration.find(params[:registration_id]) end def confirm_registration @registration.update(confirmed: true) end def unconfirm_registration @registration.update(confirmed: false) end def send_notification if @registration.confirmed? RegistrationMailer.confirmed_registration(@registration.id).deliver_now else RegistrationMailer.revoked_registration(@registration.id).deliver_now end end end end end