registrations_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class RegistrationsController < Devise::RegistrationsController
  2. invisible_captcha only: :create
  3. after_filter :set_create_notice, only: :create
  4. # POST /resource
  5. def create
  6. super do |resource|
  7. handle_nonunique_email if resource.email_taken?
  8. return if performed?
  9. end
  10. end
  11. # PUT /resource
  12. def update
  13. super do |resource|
  14. handle_nonunique_email if resource.email_taken?
  15. return if performed?
  16. end
  17. end
  18. private
  19. def handle_nonunique_email
  20. resource.errors.delete(:email)
  21. if resource.errors.empty?
  22. User.find_by_email(resource.email).send_email_taken_notice
  23. if resource.persisted?
  24. resource.update_attribute(:unconfirmed_email, account_update_params[:email])
  25. flash[:notice] = I18n.t "devise.registrations.update_needs_confirmation"
  26. respond_with resource, location: after_update_path_for(resource)
  27. else
  28. respond_with resource, location: after_inactive_sign_up_path_for(resource)
  29. end
  30. end
  31. end
  32. def after_update_path_for(resource)
  33. if params[:continue].present?
  34. verifier = ActiveSupport::MessageVerifier.new(Rails.application.secrets.secret_key_base)
  35. verifier.verify(params[:continue])
  36. else
  37. edit_registration_path(resource)
  38. end
  39. end
  40. def set_create_notice
  41. if resource.errors.empty?
  42. cookies[:sweetAlert] = JSON.dump({ title: "Thanks!", text: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." })
  43. flash[:notice] = nil
  44. end
  45. end
  46. end