Class: GraphqlDevise::Mutations::SendPasswordResetWithToken

Inherits:
Base
  • Object
show all
Defined in:
lib/graphql_devise/mutations/send_password_reset_with_token.rb

Instance Method Summary collapse

Instance Method Details

#resolve(email:, redirect_url:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/graphql_devise/mutations/send_password_reset_with_token.rb', line 11

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

  resource = find_resource(:email, get_case_insensitive_field(:email, email))

  if resource
    yield resource if block_given?

    resource.send_reset_password_instructions(
      email:         email,
      provider:      'email',
      redirect_url:  redirect_url,
      template_path: ['graphql_devise/mailer']
    )

    if resource.errors.empty?
      { message: I18n.t('graphql_devise.passwords.send_instructions') }
    else
      raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), resource: resource)
    end
  else
    raise_user_error(I18n.t('graphql_devise.user_not_found'))
  end
end