闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
920 B

  1. # frozen_string_literal: true
  2. class Api::V1::Emails::ConfirmationsController < Api::BaseController
  3. before_action :doorkeeper_authorize!
  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 if current_user.confirmed? || current_user.unconfirmed_email.blank?
  17. end
  18. end