Sha256: 9e3ff0b353c7dc52b846ceaaf8963af1f9bad06c6575e72f15b32adbb454cff2

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mr_common-2.1.0 app/controllers/mr_common/registrations/confirmations_controller.rb
mr_common-2.0.0 app/controllers/mr_common/registrations/confirmations_controller.rb