setup_controller.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. class Auth::SetupController < ApplicationController
  3. layout 'auth'
  4. before_action :authenticate_user!
  5. before_action :require_unconfirmed_or_pending!
  6. before_action :set_body_classes
  7. before_action :set_user
  8. skip_before_action :require_functional!
  9. def show
  10. flash.now[:notice] = begin
  11. if @user.pending?
  12. I18n.t('devise.registrations.signed_up_but_pending')
  13. else
  14. I18n.t('devise.registrations.signed_up_but_unconfirmed')
  15. end
  16. end
  17. end
  18. def update
  19. # This allows updating the e-mail without entering a password as is required
  20. # on the account settings page; however, we only allow this for accounts
  21. # that were not confirmed yet
  22. if @user.update(user_params)
  23. redirect_to auth_setup_path, notice: I18n.t('devise.confirmations.send_instructions')
  24. else
  25. render :show
  26. end
  27. end
  28. helper_method :missing_email?
  29. private
  30. def require_unconfirmed_or_pending!
  31. redirect_to root_path if current_user.confirmed? && current_user.approved?
  32. end
  33. def set_user
  34. @user = current_user
  35. end
  36. def set_body_classes
  37. @body_classes = 'lighter'
  38. end
  39. def user_params
  40. params.require(:user).permit(:email)
  41. end
  42. def missing_email?
  43. truthy_param?(:missing_email)
  44. end
  45. end