graphql_devise 0.18.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +25 -2
- data/.gitignore +4 -0
- data/.rubocop.yml +9 -10
- data/Appraisals +72 -35
- data/CHANGELOG.md +63 -0
- data/README.md +71 -142
- data/app/controllers/graphql_devise/graphql_controller.rb +3 -3
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -5
- data/config/routes.rb +0 -2
- data/graphql_devise.gemspec +8 -6
- data/lib/generators/graphql_devise/install_generator.rb +1 -1
- data/lib/graphql_devise/concerns/additional_controller_methods.rb +48 -0
- data/lib/graphql_devise/concerns/additional_model_methods.rb +17 -0
- data/lib/graphql_devise/concerns/authenticatable.rb +1 -1
- data/lib/graphql_devise/concerns/controller_methods.rb +79 -91
- data/lib/graphql_devise/concerns/field_authentication.rb +14 -0
- data/lib/graphql_devise/concerns/set_user_by_token.rb +1 -1
- data/lib/graphql_devise/default_operations.rb +16 -0
- data/lib/graphql_devise/engine.rb +0 -2
- data/lib/graphql_devise/model/with_email_updater.rb +5 -30
- data/lib/graphql_devise/mount_method/operation_preparer.rb +0 -7
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +0 -12
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +0 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -2
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +1 -1
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +1 -1
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +0 -2
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +1 -1
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +1 -1
- data/lib/graphql_devise/mount_method/options_validator.rb +0 -3
- data/lib/graphql_devise/mount_method/supported_options.rb +0 -5
- data/lib/graphql_devise/mutations/base.rb +1 -1
- data/lib/graphql_devise/mutations/confirm_registration_with_token.rb +2 -2
- data/lib/graphql_devise/mutations/login.rb +2 -2
- data/lib/graphql_devise/mutations/register.rb +2 -2
- data/lib/graphql_devise/mutations/update_password_with_token.rb +2 -2
- data/lib/graphql_devise/resolvers/base.rb +1 -1
- data/lib/graphql_devise/resource_loader.rb +71 -39
- data/lib/graphql_devise/route_mounter.rb +13 -0
- data/lib/graphql_devise/schema_plugin.rb +11 -40
- data/lib/graphql_devise/types/authenticatable_type.rb +1 -1
- data/lib/graphql_devise/types/base_field.rb +9 -0
- data/lib/graphql_devise/types/base_type.rb +8 -0
- data/lib/graphql_devise/types/credential_type.rb +1 -1
- data/lib/graphql_devise/types/mutation_type.rb +1 -0
- data/lib/graphql_devise/types/query_type.rb +1 -0
- data/lib/graphql_devise/version.rb +1 -1
- data/lib/graphql_devise.rb +21 -29
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +2 -16
- data/spec/dummy/app/graphql/dummy_schema.rb +1 -5
- data/spec/dummy/app/graphql/interpreter_schema.rb +6 -2
- data/spec/dummy/app/graphql/mutations/base_mutation.rb +6 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +2 -4
- data/spec/dummy/app/graphql/types/admin_type.rb +1 -1
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +1 -1
- data/spec/dummy/app/graphql/types/mutation_type.rb +3 -1
- data/spec/dummy/app/graphql/types/query_type.rb +3 -1
- data/spec/dummy/app/graphql/types/user_type.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/routes.rb +5 -9
- data/spec/generators/graphql_devise/install_generator_spec.rb +2 -2
- data/spec/graphql_devise/model/with_email_updater_spec.rb +17 -35
- data/spec/rails_helper.rb +5 -5
- data/spec/requests/mutations/login_spec.rb +34 -0
- data/spec/requests/mutations/resend_confirmation_with_token_spec.rb +2 -3
- data/spec/requests/user_controller_spec.rb +1 -33
- data/spec/services/resource_loader_spec.rb +53 -3
- data/spec/spec_helper.rb +1 -1
- metadata +62 -55
- data/app/controllers/graphql_devise/concerns/additional_controller_methods.rb +0 -72
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +0 -21
- data/app/helpers/graphql_devise/mailer_helper.rb +0 -37
- data/app/models/graphql_devise/concerns/additional_model_methods.rb +0 -21
- data/app/models/graphql_devise/concerns/model.rb +0 -25
- data/lib/graphql_devise/default_operations/mutations.rb +0 -32
- data/lib/graphql_devise/default_operations/resolvers.rb +0 -14
- data/lib/graphql_devise/mutations/resend_confirmation.rb +0 -45
- data/lib/graphql_devise/mutations/send_password_reset.rb +0 -38
- data/lib/graphql_devise/mutations/sign_up.rb +0 -61
- data/lib/graphql_devise/mutations/update_password.rb +0 -46
- data/lib/graphql_devise/rails/routes.rb +0 -15
- data/lib/graphql_devise/resolvers/check_password_token.rb +0 -43
- data/lib/graphql_devise/resolvers/confirm_account.rb +0 -42
- data/spec/dummy/app/graphql/mutations/sign_up.rb +0 -14
- data/spec/dummy/app/graphql/resolvers/confirm_admin_account.rb +0 -13
- data/spec/requests/mutations/resend_confirmation_spec.rb +0 -153
- data/spec/requests/mutations/send_password_reset_spec.rb +0 -103
- data/spec/requests/mutations/sign_up_spec.rb +0 -170
- data/spec/requests/mutations/update_password_spec.rb +0 -116
- data/spec/requests/queries/check_password_token_spec.rb +0 -149
- data/spec/requests/queries/confirm_account_spec.rb +0 -137
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Concerns
|
|
5
|
-
module AdditionalControllerMethods
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
attr_accessor :client_id, :token, :resource
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def gql_devise_context(*models)
|
|
13
|
-
{
|
|
14
|
-
current_resource: authenticate_model(*models),
|
|
15
|
-
controller: self
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def authenticate_model(*models)
|
|
20
|
-
models.each do |model|
|
|
21
|
-
set_resource_by_token(model)
|
|
22
|
-
return @resource if @resource.present?
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
nil
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def resource_class(resource = nil)
|
|
29
|
-
# Return the resource class instead of looking for a Devise mapping if resource is already a resource class
|
|
30
|
-
return resource if resource.respond_to?(:find_by)
|
|
31
|
-
|
|
32
|
-
super
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def full_url_without_params
|
|
36
|
-
request.base_url + request.path
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def set_resource_by_token(resource)
|
|
40
|
-
set_user_by_token(resource)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def graphql_context(resource_name)
|
|
44
|
-
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
|
|
45
|
-
`graphql_context` is deprecated and will be removed in a future version of this gem.
|
|
46
|
-
Use `gql_devise_context(model)` instead.
|
|
47
|
-
|
|
48
|
-
EXAMPLE
|
|
49
|
-
include GraphqlDevise::SetUserByToken
|
|
50
|
-
|
|
51
|
-
DummySchema.execute(params[:query], context: gql_devise_context(User))
|
|
52
|
-
DummySchema.execute(params[:query], context: gql_devise_context(User, Admin))
|
|
53
|
-
DEPRECATION
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
resource_name: resource_name,
|
|
57
|
-
controller: self
|
|
58
|
-
}
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def build_redirect_headers(access_token, client, redirect_header_options = {})
|
|
62
|
-
{
|
|
63
|
-
DeviseTokenAuth.headers_names[:"access-token"] => access_token,
|
|
64
|
-
DeviseTokenAuth.headers_names[:client] => client,
|
|
65
|
-
:config => params[:config],
|
|
66
|
-
:client_id => client,
|
|
67
|
-
:token => access_token
|
|
68
|
-
}.merge(redirect_header_options)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Concerns
|
|
5
|
-
module SetUserByToken
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
include DeviseTokenAuth::Concerns::SetUserByToken
|
|
10
|
-
include GraphqlDevise::Concerns::AdditionalControllerMethods
|
|
11
|
-
|
|
12
|
-
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
|
|
13
|
-
Including GraphqlDevise::Concerns::SetUserByToken is deprecated and will be removed in a future version of
|
|
14
|
-
this gem. Please use GraphqlDevise::SetUserByToken instead.
|
|
15
|
-
EXAMPLE
|
|
16
|
-
include GraphqlDevise::SetUserByToken
|
|
17
|
-
DEPRECATION
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module MailerHelper
|
|
5
|
-
def confirmation_query(resource_name:, token:, redirect_url:)
|
|
6
|
-
name = "#{GraphqlDevise.to_mapping_name(resource_name).camelize(:lower)}ConfirmAccount"
|
|
7
|
-
raw = <<-GRAPHQL
|
|
8
|
-
query($token:String!,$redirectUrl:String!){
|
|
9
|
-
#{name}(confirmationToken:$token,redirectUrl:$redirectUrl){
|
|
10
|
-
email
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
GRAPHQL
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
query: raw.delete("\n").delete(' ').html_safe,
|
|
17
|
-
variables: { token: token, redirectUrl: redirect_url }
|
|
18
|
-
}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def password_reset_query(token:, redirect_url:, resource_name:)
|
|
22
|
-
name = "#{GraphqlDevise.to_mapping_name(resource_name).camelize(:lower)}CheckPasswordToken"
|
|
23
|
-
raw = <<-GRAPHQL
|
|
24
|
-
query($token:String!,$redirectUrl:String!){
|
|
25
|
-
#{name}(resetPasswordToken:$token,redirectUrl:$redirectUrl){
|
|
26
|
-
email
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
GRAPHQL
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
query: raw.delete("\n").delete(' ').html_safe,
|
|
33
|
-
variables: { token: token, redirectUrl: redirect_url }
|
|
34
|
-
}
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'graphql_devise/model/with_email_updater'
|
|
4
|
-
|
|
5
|
-
module GraphqlDevise
|
|
6
|
-
module Concerns
|
|
7
|
-
module AdditionalModelMethods
|
|
8
|
-
extend ActiveSupport::Concern
|
|
9
|
-
|
|
10
|
-
class_methods do
|
|
11
|
-
def reconfirmable
|
|
12
|
-
devise_modules.include?(:confirmable) && column_names.include?('unconfirmed_email')
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def update_with_email(attributes = {})
|
|
17
|
-
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'graphql_devise/model/with_email_updater'
|
|
4
|
-
|
|
5
|
-
module GraphqlDevise
|
|
6
|
-
module Concerns
|
|
7
|
-
module Model
|
|
8
|
-
extend ActiveSupport::Concern
|
|
9
|
-
|
|
10
|
-
included do
|
|
11
|
-
include DeviseTokenAuth::Concerns::User
|
|
12
|
-
include GraphqlDevise::Concerns::AdditionalModelMethods
|
|
13
|
-
|
|
14
|
-
GraphqlDevise.configure_warden_serializer_for_model(self)
|
|
15
|
-
|
|
16
|
-
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
|
|
17
|
-
Including GraphqlDevise::Concerns::Model is deprecated and will be removed in a future version of
|
|
18
|
-
this gem. Please use GraphqlDevise::Authenticatable instead.
|
|
19
|
-
EXAMPLE
|
|
20
|
-
include GraphqlDevise::Authenticatable
|
|
21
|
-
DEPRECATION
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'graphql_devise/mutations/base'
|
|
4
|
-
require 'graphql_devise/mutations/login'
|
|
5
|
-
require 'graphql_devise/mutations/logout'
|
|
6
|
-
require 'graphql_devise/mutations/resend_confirmation'
|
|
7
|
-
require 'graphql_devise/mutations/resend_confirmation_with_token'
|
|
8
|
-
require 'graphql_devise/mutations/send_password_reset'
|
|
9
|
-
require 'graphql_devise/mutations/send_password_reset_with_token'
|
|
10
|
-
require 'graphql_devise/mutations/sign_up'
|
|
11
|
-
require 'graphql_devise/mutations/register'
|
|
12
|
-
require 'graphql_devise/mutations/update_password'
|
|
13
|
-
require 'graphql_devise/mutations/update_password_with_token'
|
|
14
|
-
require 'graphql_devise/mutations/confirm_registration_with_token'
|
|
15
|
-
|
|
16
|
-
module GraphqlDevise
|
|
17
|
-
module DefaultOperations
|
|
18
|
-
MUTATIONS = {
|
|
19
|
-
login: { klass: GraphqlDevise::Mutations::Login, authenticatable: true },
|
|
20
|
-
logout: { klass: GraphqlDevise::Mutations::Logout, authenticatable: true },
|
|
21
|
-
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true, deprecation_reason: 'use register instead' },
|
|
22
|
-
register: { klass: GraphqlDevise::Mutations::Register, authenticatable: true },
|
|
23
|
-
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticatable: true, deprecation_reason: 'use update_password_with_token instead' },
|
|
24
|
-
update_password_with_token: { klass: GraphqlDevise::Mutations::UpdatePasswordWithToken, authenticatable: true },
|
|
25
|
-
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticatable: false, deprecation_reason: 'use send_password_reset_with_token instead' },
|
|
26
|
-
send_password_reset_with_token: { klass: GraphqlDevise::Mutations::SendPasswordResetWithToken, authenticatable: false },
|
|
27
|
-
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false, deprecation_reason: 'use resend_confirmation_with_token instead' },
|
|
28
|
-
resend_confirmation_with_token: { klass: GraphqlDevise::Mutations::ResendConfirmationWithToken, authenticatable: false },
|
|
29
|
-
confirm_registration_with_token: { klass: GraphqlDevise::Mutations::ConfirmRegistrationWithToken, authenticatable: true }
|
|
30
|
-
}.freeze
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'graphql_devise/resolvers/base'
|
|
4
|
-
require 'graphql_devise/resolvers/check_password_token'
|
|
5
|
-
require 'graphql_devise/resolvers/confirm_account'
|
|
6
|
-
|
|
7
|
-
module GraphqlDevise
|
|
8
|
-
module DefaultOperations
|
|
9
|
-
QUERIES = {
|
|
10
|
-
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount, deprecation_reason: 'use the new confirmation flow as it does not require this query anymore' },
|
|
11
|
-
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken, deprecation_reason: 'use the new password reset flow as it does not require this query anymore' }
|
|
12
|
-
}.freeze
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Mutations
|
|
5
|
-
class ResendConfirmation < Base
|
|
6
|
-
argument :email, String, required: true, prepare: ->(email, _) { email.downcase }
|
|
7
|
-
argument :redirect_url, String, required: true
|
|
8
|
-
|
|
9
|
-
field :message, String, null: false
|
|
10
|
-
|
|
11
|
-
def resolve(email:, redirect_url:)
|
|
12
|
-
check_redirect_url_whitelist!(redirect_url)
|
|
13
|
-
|
|
14
|
-
resource = find_confirmable_resource(email)
|
|
15
|
-
|
|
16
|
-
if resource
|
|
17
|
-
yield resource if block_given?
|
|
18
|
-
|
|
19
|
-
if resource.confirmed? && !resource.pending_reconfirmation?
|
|
20
|
-
raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed'))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
resource.send_confirmation_instructions(
|
|
24
|
-
redirect_url: redirect_url,
|
|
25
|
-
template_path: ['graphql_devise/mailer'],
|
|
26
|
-
schema_url: controller.full_url_without_params
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
{ message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
|
|
30
|
-
else
|
|
31
|
-
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def find_confirmable_resource(email)
|
|
38
|
-
email_insensitive = get_case_insensitive_field(:email, email)
|
|
39
|
-
resource = find_resource(:unconfirmed_email, email_insensitive) if resource_class.reconfirmable
|
|
40
|
-
resource ||= find_resource(:email, email_insensitive)
|
|
41
|
-
resource
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Mutations
|
|
5
|
-
class SendPasswordReset < Base
|
|
6
|
-
argument :email, String, required: true
|
|
7
|
-
argument :redirect_url, String, required: true
|
|
8
|
-
|
|
9
|
-
field :message, String, null: false
|
|
10
|
-
|
|
11
|
-
def resolve(email:, redirect_url:)
|
|
12
|
-
check_redirect_url_whitelist!(redirect_url)
|
|
13
|
-
|
|
14
|
-
resource = find_resource(:email, get_case_insensitive_field(:email, email))
|
|
15
|
-
|
|
16
|
-
if resource
|
|
17
|
-
yield resource if block_given?
|
|
18
|
-
|
|
19
|
-
resource.send_reset_password_instructions(
|
|
20
|
-
email: email,
|
|
21
|
-
provider: 'email',
|
|
22
|
-
redirect_url: redirect_url,
|
|
23
|
-
template_path: ['graphql_devise/mailer'],
|
|
24
|
-
schema_url: controller.full_url_without_params
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
if resource.errors.empty?
|
|
28
|
-
{ message: I18n.t('graphql_devise.passwords.send_instructions') }
|
|
29
|
-
else
|
|
30
|
-
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), errors: resource.errors.full_messages)
|
|
31
|
-
end
|
|
32
|
-
else
|
|
33
|
-
raise_user_error(I18n.t('graphql_devise.user_not_found'))
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Mutations
|
|
5
|
-
class SignUp < Base
|
|
6
|
-
argument :email, String, required: true
|
|
7
|
-
argument :password, String, required: true
|
|
8
|
-
argument :password_confirmation, String, required: true
|
|
9
|
-
argument :confirm_success_url, String, required: false
|
|
10
|
-
|
|
11
|
-
field :credentials,
|
|
12
|
-
GraphqlDevise::Types::CredentialType,
|
|
13
|
-
null: true,
|
|
14
|
-
description: 'Authentication credentials. Null if after signUp resource is not active for authentication (e.g. Email confirmation required).'
|
|
15
|
-
|
|
16
|
-
def resolve(confirm_success_url: nil, **attrs)
|
|
17
|
-
resource = build_resource(attrs.merge(provider: provider))
|
|
18
|
-
raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank?
|
|
19
|
-
|
|
20
|
-
redirect_url = confirm_success_url || DeviseTokenAuth.default_confirm_success_url
|
|
21
|
-
if confirmable_enabled? && redirect_url.blank?
|
|
22
|
-
raise_user_error(I18n.t('graphql_devise.registrations.missing_confirm_redirect_url'))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
check_redirect_url_whitelist!(redirect_url)
|
|
26
|
-
|
|
27
|
-
resource.skip_confirmation_notification! if resource.respond_to?(:skip_confirmation_notification!)
|
|
28
|
-
|
|
29
|
-
if resource.save
|
|
30
|
-
yield resource if block_given?
|
|
31
|
-
|
|
32
|
-
unless resource.confirmed?
|
|
33
|
-
resource.send_confirmation_instructions(
|
|
34
|
-
redirect_url: redirect_url,
|
|
35
|
-
template_path: ['graphql_devise/mailer'],
|
|
36
|
-
schema_url: controller.full_url_without_params
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
response_payload = { authenticatable: resource }
|
|
41
|
-
|
|
42
|
-
response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication?
|
|
43
|
-
|
|
44
|
-
response_payload
|
|
45
|
-
else
|
|
46
|
-
resource.try(:clean_up_passwords)
|
|
47
|
-
raise_user_error_list(
|
|
48
|
-
I18n.t('graphql_devise.registration_failed'),
|
|
49
|
-
errors: resource.errors.full_messages
|
|
50
|
-
)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
private
|
|
55
|
-
|
|
56
|
-
def build_resource(attrs)
|
|
57
|
-
resource_class.new(attrs)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Mutations
|
|
5
|
-
class UpdatePassword < Base
|
|
6
|
-
argument :password, String, required: true
|
|
7
|
-
argument :password_confirmation, String, required: true
|
|
8
|
-
argument :current_password, String, required: false
|
|
9
|
-
|
|
10
|
-
def resolve(current_password: nil, **attrs)
|
|
11
|
-
if current_resource.blank?
|
|
12
|
-
raise_user_error(I18n.t('graphql_devise.not_authenticated'))
|
|
13
|
-
elsif current_resource.provider != 'email'
|
|
14
|
-
raise_user_error(
|
|
15
|
-
I18n.t('graphql_devise.passwords.password_not_required', provider: current_resource.provider.humanize)
|
|
16
|
-
)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
if update_resource_password(current_password, attrs)
|
|
20
|
-
current_resource.allow_password_change = false if recoverable_enabled?
|
|
21
|
-
current_resource.save!
|
|
22
|
-
|
|
23
|
-
yield current_resource if block_given?
|
|
24
|
-
|
|
25
|
-
{ authenticatable: current_resource }
|
|
26
|
-
else
|
|
27
|
-
raise_user_error_list(
|
|
28
|
-
I18n.t('graphql_devise.passwords.update_password_error'),
|
|
29
|
-
errors: current_resource.errors.full_messages
|
|
30
|
-
)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
|
|
36
|
-
def update_resource_password(current_password, attrs)
|
|
37
|
-
allow_password_change = recoverable_enabled? && current_resource.allow_password_change == true
|
|
38
|
-
if DeviseTokenAuth.check_current_password_before_update == false || allow_password_change
|
|
39
|
-
current_resource.public_send(:update, attrs)
|
|
40
|
-
else
|
|
41
|
-
current_resource.public_send(:update_with_password, attrs.merge(current_password: current_password))
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActionDispatch::Routing
|
|
4
|
-
class Mapper
|
|
5
|
-
def mount_graphql_devise_for(resource, options = {})
|
|
6
|
-
clean_options = GraphqlDevise::ResourceLoader.new(resource, options, true).call(
|
|
7
|
-
GraphqlDevise::Types::QueryType,
|
|
8
|
-
GraphqlDevise::Types::MutationType
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
post clean_options.at, to: 'graphql_devise/graphql#auth'
|
|
12
|
-
get clean_options.at, to: 'graphql_devise/graphql#auth'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Resolvers
|
|
5
|
-
class CheckPasswordToken < Base
|
|
6
|
-
argument :reset_password_token, String, required: true
|
|
7
|
-
argument :redirect_url, String, required: false
|
|
8
|
-
|
|
9
|
-
def resolve(reset_password_token:, redirect_url: nil)
|
|
10
|
-
resource = resource_class.with_reset_password_token(reset_password_token)
|
|
11
|
-
raise_user_error(I18n.t('graphql_devise.passwords.reset_token_not_found')) if resource.blank?
|
|
12
|
-
|
|
13
|
-
if resource.reset_password_period_valid?
|
|
14
|
-
token_info = client_and_token(resource.create_token)
|
|
15
|
-
|
|
16
|
-
resource.skip_confirmation! if confirmable_enabled? && !resource.confirmed_at
|
|
17
|
-
resource.allow_password_change = true if recoverable_enabled?
|
|
18
|
-
|
|
19
|
-
resource.save!
|
|
20
|
-
|
|
21
|
-
yield resource if block_given?
|
|
22
|
-
|
|
23
|
-
redirect_header_options = { reset_password: true }
|
|
24
|
-
built_redirect_headers = redirect_headers(
|
|
25
|
-
token_info,
|
|
26
|
-
redirect_header_options
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
if redirect_url.present?
|
|
30
|
-
check_redirect_url_whitelist!(redirect_url)
|
|
31
|
-
controller.redirect_to(resource.build_auth_url(redirect_url, built_redirect_headers))
|
|
32
|
-
else
|
|
33
|
-
set_auth_headers(resource)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
resource
|
|
37
|
-
else
|
|
38
|
-
raise_user_error(I18n.t('graphql_devise.passwords.reset_token_expired'))
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GraphqlDevise
|
|
4
|
-
module Resolvers
|
|
5
|
-
class ConfirmAccount < Base
|
|
6
|
-
argument :confirmation_token, String, required: true
|
|
7
|
-
argument :redirect_url, String, required: true
|
|
8
|
-
|
|
9
|
-
def resolve(confirmation_token:, redirect_url:)
|
|
10
|
-
check_redirect_url_whitelist!(redirect_url)
|
|
11
|
-
|
|
12
|
-
resource = resource_class.confirm_by_token(confirmation_token)
|
|
13
|
-
|
|
14
|
-
if resource.errors.empty?
|
|
15
|
-
yield resource if block_given?
|
|
16
|
-
|
|
17
|
-
redirect_header_options = { account_confirmation_success: true }
|
|
18
|
-
|
|
19
|
-
redirect_to_link = if controller.signed_in?(resource_name)
|
|
20
|
-
url = resource.build_auth_url(
|
|
21
|
-
redirect_url,
|
|
22
|
-
redirect_headers(
|
|
23
|
-
client_and_token(resource.create_token),
|
|
24
|
-
redirect_header_options
|
|
25
|
-
)
|
|
26
|
-
)
|
|
27
|
-
resource.save!
|
|
28
|
-
|
|
29
|
-
url
|
|
30
|
-
else
|
|
31
|
-
DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
controller.redirect_to(redirect_to_link)
|
|
35
|
-
resource
|
|
36
|
-
else
|
|
37
|
-
raise_user_error(I18n.t('graphql_devise.confirmations.invalid_token'))
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mutations
|
|
4
|
-
class SignUp < GraphqlDevise::Mutations::SignUp
|
|
5
|
-
argument :name, String, required: false
|
|
6
|
-
|
|
7
|
-
field :user, Types::UserType, null: true
|
|
8
|
-
|
|
9
|
-
def resolve(email:, **attrs)
|
|
10
|
-
original_payload = super
|
|
11
|
-
original_payload.merge(user: original_payload[:authenticatable])
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Resolvers
|
|
4
|
-
class ConfirmAdminAccount < GraphqlDevise::Resolvers::ConfirmAccount
|
|
5
|
-
type Types::AdminType, null: false
|
|
6
|
-
|
|
7
|
-
def resolve(confirmation_token:, redirect_url:)
|
|
8
|
-
super do |admin|
|
|
9
|
-
controller.sign_in(admin)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|