graphql_devise 0.11.4 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +7 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +2 -0
- data/README.md +219 -20
- data/Rakefile +2 -0
- data/app/controllers/graphql_devise/application_controller.rb +6 -5
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +31 -0
- data/app/controllers/graphql_devise/graphql_controller.rb +4 -0
- data/app/helpers/graphql_devise/application_helper.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +4 -2
- data/app/models/graphql_devise/concerns/model.rb +10 -0
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +4 -0
- data/graphql_devise.gemspec +6 -4
- data/lib/generators/graphql_devise/install_generator.rb +30 -5
- data/lib/graphql_devise.rb +26 -10
- data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
- data/lib/graphql_devise/default_operations/mutations.rb +8 -6
- data/lib/graphql_devise/default_operations/resolvers.rb +4 -2
- data/lib/graphql_devise/engine.rb +2 -0
- data/lib/graphql_devise/errors/authentication_error.rb +9 -0
- data/lib/graphql_devise/{detailed_user_error.rb → errors/detailed_user_error.rb} +3 -1
- data/lib/graphql_devise/errors/error_codes.rb +8 -0
- data/lib/graphql_devise/errors/execution_error.rb +6 -0
- data/lib/graphql_devise/{user_error.rb → errors/user_error.rb} +3 -1
- data/lib/graphql_devise/model/with_email_updater.rb +74 -0
- data/lib/graphql_devise/mount_method/operation_preparer.rb +4 -2
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +8 -2
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +5 -2
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +4 -2
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
- data/lib/graphql_devise/mutations/base.rb +2 -0
- data/lib/graphql_devise/mutations/login.rb +2 -0
- data/lib/graphql_devise/mutations/logout.rb +2 -0
- data/lib/graphql_devise/mutations/resend_confirmation.rb +5 -5
- data/lib/graphql_devise/mutations/send_password_reset.rb +7 -2
- data/lib/graphql_devise/mutations/sign_up.rb +5 -6
- data/lib/graphql_devise/mutations/update_password.rb +2 -0
- data/lib/graphql_devise/rails/routes.rb +7 -72
- data/lib/graphql_devise/resolvers/base.rb +2 -0
- data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
- data/lib/graphql_devise/resolvers/confirm_account.rb +4 -2
- data/lib/graphql_devise/resolvers/dummy.rb +2 -0
- data/lib/graphql_devise/resource_loader.rb +89 -0
- data/lib/graphql_devise/schema.rb +2 -0
- data/lib/graphql_devise/schema_plugin.rb +114 -0
- data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
- data/lib/graphql_devise/types/credential_type.rb +2 -0
- data/lib/graphql_devise/types/mutation_type.rb +2 -0
- data/lib/graphql_devise/types/query_type.rb +2 -0
- data/lib/graphql_devise/version.rb +3 -1
- data/spec/dummy/Rakefile +2 -0
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +38 -3
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +21 -0
- data/spec/dummy/app/graphql/interpreter_schema.rb +11 -0
- data/spec/dummy/app/graphql/mutations/login.rb +2 -0
- data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
- data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
- data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
- data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
- data/spec/dummy/app/graphql/types/base_object.rb +2 -0
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
- data/spec/dummy/app/graphql/types/mutation_type.rb +4 -1
- data/spec/dummy/app/graphql/types/query_type.rb +12 -0
- data/spec/dummy/app/graphql/types/user_type.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +2 -0
- data/spec/dummy/app/models/admin.rb +2 -0
- data/spec/dummy/app/models/application_record.rb +2 -0
- data/spec/dummy/app/models/guest.rb +2 -0
- data/spec/dummy/app/models/schema_user.rb +13 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/models/users.rb +2 -0
- data/spec/dummy/app/models/users/customer.rb +2 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cors.rb +2 -0
- data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/i18n.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/puma.rb +2 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/spring.rb +2 -0
- data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
- data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
- data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
- data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
- data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
- data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
- data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
- data/spec/dummy/db/schema.rb +30 -2
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/factories/admins.rb +2 -0
- data/spec/factories/guests.rb +2 -0
- data/spec/factories/schema_users.rb +13 -0
- data/spec/factories/users.rb +2 -0
- data/spec/factories/users_customers.rb +2 -0
- data/spec/generators/graphql_devise/install_generator_spec.rb +23 -0
- data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
- data/spec/graphql_devise_spec.rb +2 -0
- data/spec/models/user_spec.rb +2 -0
- data/spec/rails_helper.rb +3 -1
- data/spec/requests/graphql_controller_spec.rb +82 -0
- data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
- data/spec/requests/mutations/additional_queries_spec.rb +2 -0
- data/spec/requests/mutations/login_spec.rb +2 -0
- data/spec/requests/mutations/logout_spec.rb +2 -0
- data/spec/requests/mutations/resend_confirmation_spec.rb +46 -29
- data/spec/requests/mutations/send_password_reset_spec.rb +42 -12
- data/spec/requests/mutations/sign_up_spec.rb +2 -0
- data/spec/requests/mutations/update_password_spec.rb +2 -0
- data/spec/requests/queries/check_password_token_spec.rb +2 -0
- data/spec/requests/queries/confirm_account_spec.rb +9 -1
- data/spec/requests/user_controller_spec.rb +237 -23
- data/spec/services/mount_method/operation_preparer_spec.rb +10 -3
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +3 -1
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +17 -8
- data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +20 -4
- data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +3 -1
- data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/options_validator_spec.rb +2 -0
- data/spec/services/resource_loader_spec.rb +84 -0
- data/spec/services/schema_plugin_spec.rb +28 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/contexts/graphql_request.rb +2 -0
- data/spec/support/factory_bot.rb +2 -0
- data/spec/support/matchers/auth_headers_matcher.rb +2 -0
- data/spec/support/matchers/not_change_matcher.rb +2 -0
- data/spec/support/requests/auth_helpers.rb +2 -0
- data/spec/support/requests/json_helpers.rb +2 -0
- metadata +120 -87
- data/lib/graphql_devise/error_codes.rb +0 -5
- data/spec/support/generators/file_helpers.rb +0 -12
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
class ApplicationController < DeviseTokenAuth::ApplicationController
|
3
|
-
private
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
module GraphqlDevise
|
4
|
+
ApplicationController = if Rails::VERSION::MAJOR >= 5
|
5
|
+
Class.new(ActionController::API)
|
6
|
+
else
|
7
|
+
Class.new(ActionController::Base)
|
7
8
|
end
|
8
9
|
end
|
@@ -1,5 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module Concerns
|
3
5
|
SetUserByToken = DeviseTokenAuth::Concerns::SetUserByToken
|
6
|
+
|
7
|
+
SetUserByToken.module_eval do
|
8
|
+
attr_accessor :client_id, :token, :resource
|
9
|
+
|
10
|
+
def full_url_without_params
|
11
|
+
request.base_url + request.path
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_resource_by_token(resource)
|
15
|
+
set_user_by_token(resource)
|
16
|
+
end
|
17
|
+
|
18
|
+
def graphql_context(resource_name)
|
19
|
+
{
|
20
|
+
resource_name: resource_name,
|
21
|
+
controller: self
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_redirect_headers(access_token, client, redirect_header_options = {})
|
26
|
+
{
|
27
|
+
DeviseTokenAuth.headers_names[:"access-token"] => access_token,
|
28
|
+
DeviseTokenAuth.headers_names[:client] => client,
|
29
|
+
:config => params[:config],
|
30
|
+
:client_id => client,
|
31
|
+
:token => access_token
|
32
|
+
}.merge(redirect_header_options)
|
33
|
+
end
|
34
|
+
end
|
4
35
|
end
|
5
36
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_dependency 'graphql_devise/application_controller'
|
2
4
|
|
3
5
|
module GraphqlDevise
|
4
6
|
class GraphqlController < ApplicationController
|
7
|
+
include GraphqlDevise::Concerns::SetUserByToken
|
8
|
+
|
5
9
|
def auth
|
6
10
|
result = if params[:_json]
|
7
11
|
GraphqlDevise::Schema.multiplex(
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
module MailerHelper
|
3
5
|
def confirmation_query(resource_name:, token:, redirect_url:)
|
4
|
-
name = "#{resource_name.camelize(:lower)}ConfirmAccount"
|
6
|
+
name = "#{resource_name.underscore.tr('/', '_').camelize(:lower)}ConfirmAccount"
|
5
7
|
raw = <<-GRAPHQL
|
6
8
|
query($token:String!,$redirectUrl:String!){
|
7
9
|
#{name}(confirmationToken:$token,redirectUrl:$redirectUrl){
|
@@ -17,7 +19,7 @@ module GraphqlDevise
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def password_reset_query(token:, redirect_url:, resource_name:)
|
20
|
-
name = "#{resource_name.camelize(:lower)}CheckPasswordToken"
|
22
|
+
name = "#{resource_name.underscore.tr('/', '_').camelize(:lower)}CheckPasswordToken"
|
21
23
|
raw = <<-GRAPHQL
|
22
24
|
query($token:String!,$redirectUrl:String!){
|
23
25
|
#{name}(resetPasswordToken:$token,redirectUrl:$redirectUrl){
|
@@ -1,5 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_devise/model/with_email_updater'
|
4
|
+
|
1
5
|
module GraphqlDevise
|
2
6
|
module Concerns
|
3
7
|
Model = DeviseTokenAuth::Concerns::User
|
8
|
+
|
9
|
+
Model.module_eval do
|
10
|
+
def update_with_email(attributes = {})
|
11
|
+
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
|
12
|
+
end
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
<p><%= t('.confirm_link_msg') %></p>
|
4
4
|
|
5
|
-
<p><%= link_to t('.confirm_account_link'),
|
5
|
+
<p><%= link_to t('.confirm_account_link'), "#{message['schema_url']}?#{confirmation_query(resource_name: @resource.class.to_s, redirect_url: message['redirect-url'], token: @token).to_query}" %></p>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<p><%= t('.request_reset_link_msg') %></p>
|
4
4
|
|
5
|
-
<p><%= link_to t('.password_change_link'),
|
5
|
+
<p><%= link_to t('.password_change_link'), "#{message['schema_url']}?#{password_reset_query(token: @token, redirect_url: message['redirect-url'], resource_name: @resource.class.to_s).to_query}" %></p>
|
6
6
|
|
7
7
|
<p><%= t('.ignore_mail_msg') %></p>
|
8
8
|
<p><%= t('.no_changes_msg') %></p>
|
data/config/locales/en.yml
CHANGED
@@ -14,6 +14,7 @@ en:
|
|
14
14
|
password_not_required: "This account does not require a password. Sign in using your '%{provider}' account instead."
|
15
15
|
reset_token_not_found: "No user found for the specified reset token."
|
16
16
|
reset_token_expired: "Reset password token is no longer valid."
|
17
|
+
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
|
17
18
|
sessions:
|
18
19
|
bad_credentials: "Invalid login credentials. Please try again."
|
19
20
|
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"
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
GraphqlDevise::Engine.routes.draw do
|
2
4
|
# Required as Devise forces routes to reload on eager_load
|
3
5
|
unless GraphqlDevise.schema_loaded?
|
@@ -12,5 +14,7 @@ GraphqlDevise::Engine.routes.draw do
|
|
12
14
|
GraphqlDevise::Schema.query(GraphqlDevise::Types::QueryType)
|
13
15
|
|
14
16
|
GraphqlDevise.load_schema
|
17
|
+
|
18
|
+
Devise.mailer.helper(GraphqlDevise::MailerHelper)
|
15
19
|
end
|
16
20
|
end
|
data/graphql_devise.gemspec
CHANGED
@@ -21,13 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.bindir = 'exe'
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
|
-
spec.test_files = Dir
|
24
|
+
spec.test_files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").select { |f| f.match(%r{^spec/}) }
|
26
|
+
end
|
25
27
|
|
26
28
|
spec.required_ruby_version = '>= 2.2.0'
|
27
29
|
|
28
|
-
spec.add_dependency 'devise_token_auth', '>= 0.1.43'
|
29
|
-
spec.add_dependency 'graphql', '>= 1.8'
|
30
|
-
spec.add_dependency 'rails', '>= 4.2'
|
30
|
+
spec.add_dependency 'devise_token_auth', '>= 0.1.43', '< 2.0'
|
31
|
+
spec.add_dependency 'graphql', '>= 1.8', '< 1.12.0'
|
32
|
+
spec.add_dependency 'rails', '>= 4.2', '< 6.2'
|
31
33
|
|
32
34
|
spec.add_development_dependency 'appraisal'
|
33
35
|
spec.add_development_dependency 'coveralls'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GraphqlDevise
|
2
4
|
class InstallGenerator < ::Rails::Generators::Base
|
3
5
|
source_root File.expand_path('templates', __dir__)
|
@@ -5,6 +7,8 @@ module GraphqlDevise
|
|
5
7
|
argument :user_class, type: :string, default: 'User'
|
6
8
|
argument :mount_path, type: :string, default: 'auth'
|
7
9
|
|
10
|
+
class_option :mount, type: :string, default: 'separate_route'
|
11
|
+
|
8
12
|
def execute_devise_installer
|
9
13
|
generate 'devise:install'
|
10
14
|
end
|
@@ -29,15 +33,20 @@ module GraphqlDevise
|
|
29
33
|
|
30
34
|
def mount_resource_route
|
31
35
|
routes_file = 'config/routes.rb'
|
32
|
-
gem_route = "mount_graphql_devise_for '#{user_class}', at: '#{mount_path}'"
|
33
36
|
dta_route = "mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'"
|
34
37
|
|
35
|
-
if
|
38
|
+
if options['mount'] != 'separate_route'
|
36
39
|
gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '')
|
37
|
-
|
38
|
-
say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}")
|
39
40
|
else
|
40
|
-
|
41
|
+
gem_route = "mount_graphql_devise_for '#{user_class}', at: '#{mount_path}'"
|
42
|
+
|
43
|
+
if file_contains_str?(routes_file, gem_route)
|
44
|
+
gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '')
|
45
|
+
|
46
|
+
say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}")
|
47
|
+
else
|
48
|
+
gsub_file(routes_file, /#{Regexp.escape(dta_route)}/i, gem_route)
|
49
|
+
end
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
@@ -65,6 +74,22 @@ module GraphqlDevise
|
|
65
74
|
)
|
66
75
|
end
|
67
76
|
|
77
|
+
def mount_in_schema
|
78
|
+
return if options['mount'] == 'separate_route'
|
79
|
+
|
80
|
+
inject_into_file "app/graphql/#{options['mount'].underscore}.rb", after: "< GraphQL::Schema\n" do
|
81
|
+
<<-RUBY
|
82
|
+
use GraphqlDevise::SchemaPlugin.new(
|
83
|
+
query: Types::QueryType,
|
84
|
+
mutation: Types::MutationType,
|
85
|
+
resource_loaders: [
|
86
|
+
GraphqlDevise::ResourceLoader.new('#{user_class}'),
|
87
|
+
]
|
88
|
+
)
|
89
|
+
RUBY
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
68
93
|
private
|
69
94
|
|
70
95
|
def file_contains_str?(filename, regex_str)
|
data/lib/graphql_devise.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails'
|
2
4
|
require 'graphql'
|
3
5
|
require 'devise_token_auth'
|
@@ -18,15 +20,32 @@ module GraphqlDevise
|
|
18
20
|
@schema_loaded = true
|
19
21
|
end
|
20
22
|
|
21
|
-
def self.
|
22
|
-
@mounted_resources
|
23
|
+
def self.resource_mounted?(mapping_name)
|
24
|
+
@mounted_resources.include?(mapping_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.mount_resource(mapping_name)
|
28
|
+
@mounted_resources << mapping_name
|
23
29
|
end
|
24
30
|
|
25
|
-
def self.
|
26
|
-
|
31
|
+
def self.add_mapping(mapping_name, resource)
|
32
|
+
return if Devise.mappings.key?(mapping_name)
|
33
|
+
|
34
|
+
Devise.add_mapping(
|
35
|
+
mapping_name.to_s.pluralize.to_sym,
|
36
|
+
module: :devise, class_name: resource
|
37
|
+
)
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
41
|
+
require 'graphql_devise/engine'
|
42
|
+
require 'graphql_devise/version'
|
43
|
+
require 'graphql_devise/errors/error_codes'
|
44
|
+
require 'graphql_devise/errors/execution_error'
|
45
|
+
require 'graphql_devise/errors/user_error'
|
46
|
+
require 'graphql_devise/errors/authentication_error'
|
47
|
+
require 'graphql_devise/errors/detailed_user_error'
|
48
|
+
|
30
49
|
require 'graphql_devise/concerns/controller_methods'
|
31
50
|
require 'graphql_devise/schema'
|
32
51
|
require 'graphql_devise/types/authenticatable_type'
|
@@ -37,13 +56,10 @@ require 'graphql_devise/default_operations/mutations'
|
|
37
56
|
require 'graphql_devise/default_operations/resolvers'
|
38
57
|
require 'graphql_devise/resolvers/dummy'
|
39
58
|
|
40
|
-
require 'graphql_devise/engine'
|
41
|
-
require 'graphql_devise/version'
|
42
|
-
require 'graphql_devise/error_codes'
|
43
|
-
require 'graphql_devise/user_error'
|
44
|
-
require 'graphql_devise/detailed_user_error'
|
45
|
-
|
46
59
|
require 'graphql_devise/mount_method/option_sanitizer'
|
47
60
|
require 'graphql_devise/mount_method/options_validator'
|
48
61
|
require 'graphql_devise/mount_method/operation_preparer'
|
49
62
|
require 'graphql_devise/mount_method/operation_sanitizer'
|
63
|
+
|
64
|
+
require 'graphql_devise/resource_loader'
|
65
|
+
require 'graphql_devise/schema_plugin'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'graphql_devise/mutations/base'
|
2
4
|
require 'graphql_devise/mutations/login'
|
3
5
|
require 'graphql_devise/mutations/logout'
|
@@ -9,12 +11,12 @@ require 'graphql_devise/mutations/update_password'
|
|
9
11
|
module GraphqlDevise
|
10
12
|
module DefaultOperations
|
11
13
|
MUTATIONS = {
|
12
|
-
login: GraphqlDevise::Mutations::Login,
|
13
|
-
logout: GraphqlDevise::Mutations::Logout,
|
14
|
-
sign_up: GraphqlDevise::Mutations::SignUp,
|
15
|
-
update_password: GraphqlDevise::Mutations::UpdatePassword,
|
16
|
-
send_password_reset: GraphqlDevise::Mutations::SendPasswordReset,
|
17
|
-
resend_confirmation: GraphqlDevise::Mutations::ResendConfirmation
|
14
|
+
login: { klass: GraphqlDevise::Mutations::Login, authenticatable: true },
|
15
|
+
logout: { klass: GraphqlDevise::Mutations::Logout, authenticatable: true },
|
16
|
+
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true },
|
17
|
+
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticatable: true },
|
18
|
+
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticatable: false },
|
19
|
+
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false }
|
18
20
|
}.freeze
|
19
21
|
end
|
20
22
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'graphql_devise/resolvers/base'
|
2
4
|
require 'graphql_devise/resolvers/check_password_token'
|
3
5
|
require 'graphql_devise/resolvers/confirm_account'
|
@@ -5,8 +7,8 @@ require 'graphql_devise/resolvers/confirm_account'
|
|
5
7
|
module GraphqlDevise
|
6
8
|
module DefaultOperations
|
7
9
|
QUERIES = {
|
8
|
-
confirm_account: GraphqlDevise::Resolvers::ConfirmAccount,
|
9
|
-
check_password_token: GraphqlDevise::Resolvers::CheckPasswordToken
|
10
|
+
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount },
|
11
|
+
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken }
|
10
12
|
}.freeze
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlDevise
|
4
|
+
module Model
|
5
|
+
class WithEmailUpdater
|
6
|
+
def initialize(resource, attributes)
|
7
|
+
@attributes = attributes
|
8
|
+
@resource = resource
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
resource_attributes = @attributes.except(:schema_url, :confirmation_success_url)
|
13
|
+
return @resource.update(resource_attributes) unless requires_reconfirmation?(resource_attributes)
|
14
|
+
|
15
|
+
@resource.assign_attributes(resource_attributes)
|
16
|
+
|
17
|
+
if @resource.email == email_in_database
|
18
|
+
return @resource.save
|
19
|
+
elsif required_reconfirm_attributes?
|
20
|
+
return false unless @resource.valid?
|
21
|
+
|
22
|
+
store_unconfirmed_email
|
23
|
+
saved = @resource.save
|
24
|
+
send_confirmation_instructions(saved)
|
25
|
+
|
26
|
+
saved
|
27
|
+
else
|
28
|
+
raise(
|
29
|
+
GraphqlDevise::Error,
|
30
|
+
'Method `update_with_email` requires attributes `confirmation_success_url` and `schema_url` for email reconfirmation to work'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def required_reconfirm_attributes?
|
38
|
+
@attributes[:schema_url].present? &&
|
39
|
+
(@attributes[:confirmation_success_url].present? || DeviseTokenAuth.default_confirm_success_url.present?)
|
40
|
+
end
|
41
|
+
|
42
|
+
def requires_reconfirmation?(resource_attributes)
|
43
|
+
resource_attributes.key?(:email) &&
|
44
|
+
@resource.devise_modules.include?(:confirmable) &&
|
45
|
+
@resource.respond_to?(:unconfirmed_email=)
|
46
|
+
end
|
47
|
+
|
48
|
+
def store_unconfirmed_email
|
49
|
+
@resource.unconfirmed_email = @resource.email
|
50
|
+
@resource.confirmation_token = nil
|
51
|
+
@resource.email = email_in_database
|
52
|
+
@resource.send(:generate_confirmation_token)
|
53
|
+
end
|
54
|
+
|
55
|
+
def email_in_database
|
56
|
+
if Devise.activerecord51?
|
57
|
+
@resource.email_in_database
|
58
|
+
else
|
59
|
+
@resource.email_was
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def send_confirmation_instructions(saved)
|
64
|
+
return unless saved
|
65
|
+
|
66
|
+
@resource.send_confirmation_instructions(
|
67
|
+
redirect_url: @attributes[:confirmation_success_url] || DeviseTokenAuth.default_confirm_success_url,
|
68
|
+
template_path: ['graphql_devise/mailer'],
|
69
|
+
schema_url: @attributes[:schema_url]
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|