1
0

confirmations_controller.rb 917 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. module Admin
  3. class ConfirmationsController < BaseController
  4. before_action :set_user
  5. before_action :check_confirmation, only: [:resend]
  6. def create
  7. authorize @user, :confirm?
  8. @user.confirm!
  9. log_action :confirm, @user
  10. redirect_to admin_accounts_path
  11. end
  12. def resend
  13. authorize @user, :confirm?
  14. @user.resend_confirmation_instructions
  15. log_action :confirm, @user
  16. flash[:notice] = I18n.t('admin.accounts.resend_confirmation.success')
  17. redirect_to admin_accounts_path
  18. end
  19. private
  20. def set_user
  21. @user = Account.find(params[:account_id]).user || raise(ActiveRecord::RecordNotFound)
  22. end
  23. def check_confirmation
  24. if @user.confirmed?
  25. flash[:error] = I18n.t('admin.accounts.resend_confirmation.already_confirmed')
  26. redirect_to admin_accounts_path
  27. end
  28. end
  29. end
  30. end