Sha256: 7e02e9680adbf0f2f8c77c28a4615e7155bb609fa118a70c5d3fd1ff49f634e2

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module GraphqlDevise
  module Mutations
    class ResendConfirmation < Base
      argument :email,        String, required: true, prepare: ->(email, _) { email.downcase }
      argument :redirect_url, String, required: true

      field :message, String, null: false

      def resolve(email:, redirect_url:)
        check_redirect_url_whitelist!(redirect_url)

        resource = find_confirmable_resource(email)

        if resource
          yield resource if block_given?

          if resource.confirmed? && !resource.pending_reconfirmation?
            raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed'))
          end

          resource.send_confirmation_instructions(
            redirect_url:  redirect_url,
            template_path: ['graphql_devise/mailer'],
            schema_url:    controller.full_url_without_params
          )

          { message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
        else
          raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
        end
      end

      private

      def find_confirmable_resource(email)
        email_insensitive = get_case_insensitive_field(:email, email)
        resource = find_resource(:unconfirmed_email, email_insensitive) if resource_class.reconfirmable
        resource ||= find_resource(:email, email_insensitive)
        resource
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql_devise-0.18.2 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.18.1 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.18.0 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.17.1 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.17.0 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.16.0 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.15.0 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.14.3 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.14.2 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.14.1 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.14.0 lib/graphql_devise/mutations/resend_confirmation.rb
graphql_devise-0.13.6 lib/graphql_devise/mutations/resend_confirmation.rb