confirmations_controller.rb 959 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class Api::V1::Emails::ConfirmationsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
  4. before_action :require_user_owned_by_application!
  5. before_action :require_user_not_confirmed!
  6. def create
  7. current_user.update!(email: params[:email]) if params.key?(:email)
  8. current_user.resend_confirmation_instructions
  9. render_empty
  10. end
  11. private
  12. def require_user_owned_by_application!
  13. render json: { error: 'This method is only available to the application the user originally signed-up with' }, status: :forbidden unless current_user && current_user.created_by_application_id == doorkeeper_token.application_id
  14. end
  15. def require_user_not_confirmed!
  16. render json: { error: 'This method is only available while the e-mail is awaiting confirmation' }, status: :forbidden unless !current_user.confirmed? || current_user.unconfirmed_email.present?
  17. end
  18. end