Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ is `User`.
1. userSignUp
1. userUpdatePassword
1. userSendPasswordReset
1. `userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload`
Comment thread
aarona marked this conversation as resolved.

The `UserResendConfirmationPayload` will return the `authenticable` resource that was sent the confirmation instructions but also has a `message: String!` that can be used to notify a user what to do after the instructions were sent to them and a `success: Boolean!` to indicate success.
#### Queries
1. userConfirmAccount
1. userCheckPasswordToken
Expand Down
30 changes: 30 additions & 0 deletions app/graphql/graphql_devise/mutations/resend_confirmation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module GraphqlDevise
module Mutations
class ResendConfirmation < Base
argument :email, String, required: true, prepare: ->(email, _) { email.downcase }
argument :redirect_url, String, required: true

field :success, Boolean, null: false
Comment thread
aarona marked this conversation as resolved.
Outdated
field :message, String, null: false
Comment thread
aarona marked this conversation as resolved.

def resolve(email:, redirect_url:)
resource = controller.find_resource(:uid, email)

if resource
yield resource if block_given?
resource.send_confirmation_instructions({
redirect_url: redirect_url,
template_path: ['graphql_devise/mailer']
})

{
success: true,
Comment thread
aarona marked this conversation as resolved.
Outdated
message: I18n.t('graphql_devise.confirmations.send_instructions', email: email)
}
Comment thread
aarona marked this conversation as resolved.
else
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p><%= t(:welcome).capitalize + ' ' + @email %>!</p>

<p><%= t '.confirm_link_msg' %> </p>
<p><%= t '.confirm_link_msg' %></p>

<p><%= link_to t('.confirm_account_link'), url_for(controller: 'graphql_devise/graphql', action: :auth, **confirmation_query(resource_name: @resource.class.to_s, redirect_url: message['redirect-url'], token: @token)) %></p>
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ en:
not_confirmed: "A confirmation email was sent to your account at '%{email}'. You must follow the instructions in the email before your account can be activated"
confirmations:
invalid_token: "Invalid confirmation token. Please try again"
user_not_found: "Unable to find user with email '%{email}'."
Comment thread
aarona marked this conversation as resolved.
sended: "An email has been sent to '%{email}' containing instructions for confirming your account."
Comment thread
aarona marked this conversation as resolved.
Outdated
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
Comment thread
aarona marked this conversation as resolved.
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
mailer:
confirmation_instructions:
confirm_link_msg: "You can confirm your account email through the link below:"
confirm_account_link: "Confirm my account"
unlock_instructions:
account_lock_msg: "Your account has been locked due to an excessive number of unsuccessful sign in attempts."
3 changes: 2 additions & 1 deletion lib/graphql_devise/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def mount_graphql_devise_for(resource, opts = {})
logout: GraphqlDevise::Mutations::Logout,
sign_up: GraphqlDevise::Mutations::SignUp,
update_password: GraphqlDevise::Mutations::UpdatePassword,
send_password_reset: GraphqlDevise::Mutations::SendPasswordReset
send_password_reset: GraphqlDevise::Mutations::SendPasswordReset,
resend_confirmation: GraphqlDevise::Mutations::ResendConfirmation
}.freeze
default_queries = {
confirm_account: GraphqlDevise::Resolvers::ConfirmAccount,
Expand Down
51 changes: 51 additions & 0 deletions spec/requests/mutations/resend_confirmation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'rails_helper'

RSpec.describe 'Resend confirmation' do
include_context 'with graphql query request'

let(:user) { create(:user, confirmed_at: nil) }
let(:email) { user.email }
let(:redirect) { Faker::Internet.url }
let(:query) do
<<-GRAPHQL
mutation {
userResendConfirmation(
email:"#{email}",
redirectUrl:"#{redirect}"
) {
message
success
}
}
GRAPHQL
end

context 'when params are correct' do
it 'sends an email to the user with confirm url' do
expect { post_request }.to(
Comment thread
aarona marked this conversation as resolved.
Outdated
change(ActionMailer::Base.deliveries, :count).by(1)
)

email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first

# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :confirmed_at).from(NilClass).to(Time)
Comment thread
aarona marked this conversation as resolved.
Outdated
end
end

context 'when the email isn''t in the system' do
Comment thread
aarona marked this conversation as resolved.
Outdated
let(:email) { 'nothere@gmail.com' }
before { post_request }
Comment thread
aarona marked this conversation as resolved.
Outdated

it 'returns an error' do
expect(json_response[:errors]).to contain_exactly(
hash_including(
message: "Unable to find user with email '#{email}'.", extensions: { code: 'USER_ERROR' })
)
end
end
end
Comment thread
aarona marked this conversation as resolved.
Outdated