ultra-max-kit 0.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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/devise-5.0.4/CHANGELOG.md +88 -0
  3. data/devise-5.0.4/MIT-LICENSE +21 -0
  4. data/devise-5.0.4/README.md +776 -0
  5. data/devise-5.0.4/app/controllers/devise/confirmations_controller.rb +54 -0
  6. data/devise-5.0.4/app/controllers/devise/omniauth_callbacks_controller.rb +36 -0
  7. data/devise-5.0.4/app/controllers/devise/passwords_controller.rb +88 -0
  8. data/devise-5.0.4/app/controllers/devise/registrations_controller.rb +169 -0
  9. data/devise-5.0.4/app/controllers/devise/sessions_controller.rb +83 -0
  10. data/devise-5.0.4/app/controllers/devise/unlocks_controller.rb +52 -0
  11. data/devise-5.0.4/app/controllers/devise_controller.rb +226 -0
  12. data/devise-5.0.4/app/helpers/devise_helper.rb +5 -0
  13. data/devise-5.0.4/app/mailers/devise/mailer.rb +30 -0
  14. data/devise-5.0.4/app/views/devise/confirmations/new.html.erb +16 -0
  15. data/devise-5.0.4/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  16. data/devise-5.0.4/app/views/devise/mailer/email_changed.html.erb +7 -0
  17. data/devise-5.0.4/app/views/devise/mailer/password_change.html.erb +3 -0
  18. data/devise-5.0.4/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/devise-5.0.4/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/devise-5.0.4/app/views/devise/passwords/edit.html.erb +25 -0
  21. data/devise-5.0.4/app/views/devise/passwords/new.html.erb +16 -0
  22. data/devise-5.0.4/app/views/devise/registrations/edit.html.erb +42 -0
  23. data/devise-5.0.4/app/views/devise/registrations/new.html.erb +29 -0
  24. data/devise-5.0.4/app/views/devise/sessions/new.html.erb +26 -0
  25. data/devise-5.0.4/app/views/devise/shared/_error_messages.html.erb +15 -0
  26. data/devise-5.0.4/app/views/devise/shared/_links.html.erb +25 -0
  27. data/devise-5.0.4/app/views/devise/unlocks/new.html.erb +16 -0
  28. data/devise-5.0.4/config/locales/en.yml +65 -0
  29. data/devise-5.0.4/lib/devise/controllers/helpers.rb +295 -0
  30. data/devise-5.0.4/lib/devise/controllers/rememberable.rb +56 -0
  31. data/devise-5.0.4/lib/devise/controllers/responder.rb +35 -0
  32. data/devise-5.0.4/lib/devise/controllers/scoped_views.rb +19 -0
  33. data/devise-5.0.4/lib/devise/controllers/sign_in_out.rb +106 -0
  34. data/devise-5.0.4/lib/devise/controllers/store_location.rb +76 -0
  35. data/devise-5.0.4/lib/devise/controllers/url_helpers.rb +69 -0
  36. data/devise-5.0.4/lib/devise/delegator.rb +18 -0
  37. data/devise-5.0.4/lib/devise/encryptor.rb +24 -0
  38. data/devise-5.0.4/lib/devise/failure_app.rb +287 -0
  39. data/devise-5.0.4/lib/devise/hooks/activatable.rb +12 -0
  40. data/devise-5.0.4/lib/devise/hooks/csrf_cleaner.rb +14 -0
  41. data/devise-5.0.4/lib/devise/hooks/forgetable.rb +11 -0
  42. data/devise-5.0.4/lib/devise/hooks/lockable.rb +9 -0
  43. data/devise-5.0.4/lib/devise/hooks/proxy.rb +23 -0
  44. data/devise-5.0.4/lib/devise/hooks/rememberable.rb +9 -0
  45. data/devise-5.0.4/lib/devise/hooks/timeoutable.rb +35 -0
  46. data/devise-5.0.4/lib/devise/hooks/trackable.rb +11 -0
  47. data/devise-5.0.4/lib/devise/mailers/helpers.rb +87 -0
  48. data/devise-5.0.4/lib/devise/mapping.rb +178 -0
  49. data/devise-5.0.4/lib/devise/models/authenticatable.rb +302 -0
  50. data/devise-5.0.4/lib/devise/models/confirmable.rb +371 -0
  51. data/devise-5.0.4/lib/devise/models/database_authenticatable.rb +204 -0
  52. data/devise-5.0.4/lib/devise/models/lockable.rb +214 -0
  53. data/devise-5.0.4/lib/devise/models/omniauthable.rb +29 -0
  54. data/devise-5.0.4/lib/devise/models/recoverable.rb +156 -0
  55. data/devise-5.0.4/lib/devise/models/registerable.rb +29 -0
  56. data/devise-5.0.4/lib/devise/models/rememberable.rb +158 -0
  57. data/devise-5.0.4/lib/devise/models/timeoutable.rb +45 -0
  58. data/devise-5.0.4/lib/devise/models/trackable.rb +51 -0
  59. data/devise-5.0.4/lib/devise/models/validatable.rb +70 -0
  60. data/devise-5.0.4/lib/devise/models.rb +122 -0
  61. data/devise-5.0.4/lib/devise/modules.rb +30 -0
  62. data/devise-5.0.4/lib/devise/omniauth/config.rb +47 -0
  63. data/devise-5.0.4/lib/devise/omniauth/url_helpers.rb +27 -0
  64. data/devise-5.0.4/lib/devise/omniauth.rb +27 -0
  65. data/devise-5.0.4/lib/devise/orm/active_record.rb +7 -0
  66. data/devise-5.0.4/lib/devise/orm/mongoid.rb +7 -0
  67. data/devise-5.0.4/lib/devise/orm.rb +80 -0
  68. data/devise-5.0.4/lib/devise/parameter_filter.rb +44 -0
  69. data/devise-5.0.4/lib/devise/parameter_sanitizer.rb +172 -0
  70. data/devise-5.0.4/lib/devise/rails/routes.rb +514 -0
  71. data/devise-5.0.4/lib/devise/rails/warden_compat.rb +15 -0
  72. data/devise-5.0.4/lib/devise/rails.rb +57 -0
  73. data/devise-5.0.4/lib/devise/strategies/authenticatable.rb +178 -0
  74. data/devise-5.0.4/lib/devise/strategies/base.rb +22 -0
  75. data/devise-5.0.4/lib/devise/strategies/database_authenticatable.rb +31 -0
  76. data/devise-5.0.4/lib/devise/strategies/rememberable.rb +67 -0
  77. data/devise-5.0.4/lib/devise/test/controller_helpers.rb +156 -0
  78. data/devise-5.0.4/lib/devise/test/integration_helpers.rb +63 -0
  79. data/devise-5.0.4/lib/devise/time_inflector.rb +16 -0
  80. data/devise-5.0.4/lib/devise/token_generator.rb +32 -0
  81. data/devise-5.0.4/lib/devise/version.rb +5 -0
  82. data/devise-5.0.4/lib/devise.rb +533 -0
  83. data/devise-5.0.4/lib/generators/active_record/devise_generator.rb +119 -0
  84. data/devise-5.0.4/lib/generators/active_record/templates/migration.rb +20 -0
  85. data/devise-5.0.4/lib/generators/active_record/templates/migration_existing.rb +27 -0
  86. data/devise-5.0.4/lib/generators/devise/controllers_generator.rb +46 -0
  87. data/devise-5.0.4/lib/generators/devise/devise_generator.rb +28 -0
  88. data/devise-5.0.4/lib/generators/devise/install_generator.rb +42 -0
  89. data/devise-5.0.4/lib/generators/devise/orm_helpers.rb +36 -0
  90. data/devise-5.0.4/lib/generators/devise/views_generator.rb +145 -0
  91. data/devise-5.0.4/lib/generators/mongoid/devise_generator.rb +57 -0
  92. data/devise-5.0.4/lib/generators/templates/README +36 -0
  93. data/devise-5.0.4/lib/generators/templates/controllers/README +14 -0
  94. data/devise-5.0.4/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  95. data/devise-5.0.4/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  96. data/devise-5.0.4/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  97. data/devise-5.0.4/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  98. data/devise-5.0.4/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  99. data/devise-5.0.4/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  100. data/devise-5.0.4/lib/generators/templates/devise.rb +316 -0
  101. data/devise-5.0.4/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  102. data/devise-5.0.4/lib/generators/templates/markerb/email_changed.markerb +7 -0
  103. data/devise-5.0.4/lib/generators/templates/markerb/password_change.markerb +3 -0
  104. data/devise-5.0.4/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  105. data/devise-5.0.4/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  106. data/devise-5.0.4/lib/generators/templates/simple_form_for/confirmations/new.html.erb +20 -0
  107. data/devise-5.0.4/lib/generators/templates/simple_form_for/passwords/edit.html.erb +27 -0
  108. data/devise-5.0.4/lib/generators/templates/simple_form_for/passwords/new.html.erb +18 -0
  109. data/devise-5.0.4/lib/generators/templates/simple_form_for/registrations/edit.html.erb +35 -0
  110. data/devise-5.0.4/lib/generators/templates/simple_form_for/registrations/new.html.erb +25 -0
  111. data/devise-5.0.4/lib/generators/templates/simple_form_for/sessions/new.html.erb +20 -0
  112. data/devise-5.0.4/lib/generators/templates/simple_form_for/unlocks/new.html.erb +19 -0
  113. data/ultra-max-kit.gemspec +12 -0
  114. metadata +153 -0
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::ConfirmationsController < DeviseController
4
+ # GET /resource/confirmation/new
5
+ def new
6
+ self.resource = resource_class.new
7
+ end
8
+
9
+ # POST /resource/confirmation
10
+ def create
11
+ self.resource = resource_class.send_confirmation_instructions(resource_params)
12
+ yield resource if block_given?
13
+
14
+ if successfully_sent?(resource)
15
+ respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
16
+ else
17
+ respond_with(resource)
18
+ end
19
+ end
20
+
21
+ # GET /resource/confirmation?confirmation_token=abcdef
22
+ def show
23
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
24
+ yield resource if block_given?
25
+
26
+ if resource.errors.empty?
27
+ set_flash_message!(:notice, :confirmed)
28
+ respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
29
+ else
30
+ # TODO: use `error_status` when the default changes to `:unprocessable_entity` / `:unprocessable_content`.
31
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ # The path used after resending confirmation instructions.
38
+ def after_resending_confirmation_instructions_path_for(resource_name)
39
+ is_navigational_format? ? new_session_path(resource_name) : '/'
40
+ end
41
+
42
+ # The path used after confirmation.
43
+ def after_confirmation_path_for(resource_name, resource)
44
+ if signed_in?(resource_name)
45
+ signed_in_root_path(resource)
46
+ else
47
+ new_session_path(resource_name)
48
+ end
49
+ end
50
+
51
+ def translation_scope
52
+ 'devise.confirmations'
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::OmniauthCallbacksController < DeviseController
4
+ prepend_before_action { request.env["devise.skip_timeout"] = true }
5
+
6
+ def passthru
7
+ render status: 404, plain: "Not found. Authentication passthru."
8
+ end
9
+
10
+ def failure
11
+ set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
12
+ redirect_to after_omniauth_failure_path_for(resource_name)
13
+ end
14
+
15
+ protected
16
+
17
+ def failed_strategy
18
+ request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : request.env["omniauth.error.strategy"]
19
+ end
20
+
21
+ def failure_message
22
+ exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : request.env["omniauth.error"]
23
+ error = exception.error_reason if exception.respond_to?(:error_reason)
24
+ error ||= exception.error if exception.respond_to?(:error)
25
+ error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : request.env["omniauth.error.type"]).to_s
26
+ error.to_s.humanize if error
27
+ end
28
+
29
+ def after_omniauth_failure_path_for(scope)
30
+ new_session_path(scope)
31
+ end
32
+
33
+ def translation_scope
34
+ 'devise.omniauth_callbacks'
35
+ end
36
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::PasswordsController < DeviseController
4
+ prepend_before_action :require_no_authentication
5
+ # Render the #edit only if coming from a reset password email link
6
+ append_before_action :assert_reset_token_passed, only: :edit
7
+
8
+ # GET /resource/password/new
9
+ def new
10
+ self.resource = resource_class.new
11
+ end
12
+
13
+ # POST /resource/password
14
+ def create
15
+ self.resource = resource_class.send_reset_password_instructions(resource_params)
16
+ yield resource if block_given?
17
+
18
+ if successfully_sent?(resource)
19
+ respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
20
+ else
21
+ respond_with(resource)
22
+ end
23
+ end
24
+
25
+ # GET /resource/password/edit?reset_password_token=abcdef
26
+ def edit
27
+ self.resource = resource_class.new
28
+ set_minimum_password_length
29
+ resource.reset_password_token = params[:reset_password_token]
30
+ end
31
+
32
+ # PUT /resource/password
33
+ def update
34
+ self.resource = resource_class.reset_password_by_token(resource_params)
35
+ yield resource if block_given?
36
+
37
+ if resource.errors.empty?
38
+ resource.unlock_access! if unlockable?(resource)
39
+ if sign_in_after_reset_password?
40
+ flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
41
+ set_flash_message!(:notice, flash_message)
42
+ resource.after_database_authentication
43
+ sign_in(resource_name, resource)
44
+ else
45
+ set_flash_message!(:notice, :updated_not_active)
46
+ end
47
+ respond_with resource, location: after_resetting_password_path_for(resource)
48
+ else
49
+ set_minimum_password_length
50
+ respond_with resource
51
+ end
52
+ end
53
+
54
+ protected
55
+ def after_resetting_password_path_for(resource)
56
+ sign_in_after_reset_password? ? after_sign_in_path_for(resource) : new_session_path(resource_name)
57
+ end
58
+
59
+ # The path used after sending reset password instructions
60
+ def after_sending_reset_password_instructions_path_for(resource_name)
61
+ new_session_path(resource_name) if is_navigational_format?
62
+ end
63
+
64
+ # Check if a reset_password_token is provided in the request
65
+ def assert_reset_token_passed
66
+ if params[:reset_password_token].blank?
67
+ set_flash_message(:alert, :no_token)
68
+ redirect_to new_session_path(resource_name)
69
+ end
70
+ end
71
+
72
+ # Check if the user should be signed in automatically after resetting the password.
73
+ def sign_in_after_reset_password?
74
+ resource_class.sign_in_after_reset_password
75
+ end
76
+
77
+ # Check if proper Lockable module methods are present & unlock strategy
78
+ # allows to unlock resource on password reset
79
+ def unlockable?(resource)
80
+ resource.respond_to?(:unlock_access!) &&
81
+ resource.respond_to?(:unlock_strategy_enabled?) &&
82
+ resource.unlock_strategy_enabled?(:email)
83
+ end
84
+
85
+ def translation_scope
86
+ 'devise.passwords'
87
+ end
88
+ end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::RegistrationsController < DeviseController
4
+ prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
5
+ prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
6
+ prepend_before_action :set_minimum_password_length, only: [:new, :edit]
7
+
8
+ # GET /resource/sign_up
9
+ def new
10
+ build_resource
11
+ yield resource if block_given?
12
+ respond_with resource
13
+ end
14
+
15
+ # POST /resource
16
+ def create
17
+ build_resource(sign_up_params)
18
+
19
+ resource.save
20
+ yield resource if block_given?
21
+ if resource.persisted?
22
+ if resource.active_for_authentication?
23
+ set_flash_message! :notice, :signed_up
24
+ sign_up(resource_name, resource)
25
+ respond_with resource, location: after_sign_up_path_for(resource)
26
+ else
27
+ set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
28
+ expire_data_after_sign_in!
29
+ respond_with resource, location: after_inactive_sign_up_path_for(resource)
30
+ end
31
+ else
32
+ clean_up_passwords resource
33
+ set_minimum_password_length
34
+ respond_with resource
35
+ end
36
+ end
37
+
38
+ # GET /resource/edit
39
+ def edit
40
+ render :edit
41
+ end
42
+
43
+ # PUT /resource
44
+ # We need to use a copy of the resource because we don't want to change
45
+ # the current user in place.
46
+ def update
47
+ self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
48
+ prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
49
+
50
+ resource_updated = update_resource(resource, account_update_params)
51
+ yield resource if block_given?
52
+ if resource_updated
53
+ set_flash_message_for_update(resource, prev_unconfirmed_email)
54
+ bypass_sign_in resource, scope: resource_name if sign_in_after_change_password?
55
+
56
+ respond_with resource, location: after_update_path_for(resource)
57
+ else
58
+ clean_up_passwords resource
59
+ set_minimum_password_length
60
+ respond_with resource
61
+ end
62
+ end
63
+
64
+ # DELETE /resource
65
+ def destroy
66
+ resource.destroy
67
+ Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
68
+ set_flash_message! :notice, :destroyed
69
+ yield resource if block_given?
70
+ respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }
71
+ end
72
+
73
+ # GET /resource/cancel
74
+ # Forces the session data which is usually expired after sign
75
+ # in to be expired now. This is useful if the user wants to
76
+ # cancel oauth signing in/up in the middle of the process,
77
+ # removing all OAuth session data.
78
+ def cancel
79
+ expire_data_after_sign_in!
80
+ redirect_to new_registration_path(resource_name)
81
+ end
82
+
83
+ protected
84
+
85
+ # By default we want to require a password checks on update.
86
+ # You can overwrite this method in your own RegistrationsController.
87
+ def update_resource(resource, params)
88
+ resource.update_with_password(params)
89
+ end
90
+
91
+ # Build a devise resource passing in the session. Useful to move
92
+ # temporary session data to the newly created user.
93
+ def build_resource(hash = {})
94
+ self.resource = resource_class.new_with_session(hash, session)
95
+ end
96
+
97
+ # Signs in a user on sign up. You can overwrite this method in your own
98
+ # RegistrationsController.
99
+ def sign_up(resource_name, resource)
100
+ sign_in(resource_name, resource)
101
+ end
102
+
103
+ # The path used after sign up. You need to overwrite this method
104
+ # in your own RegistrationsController.
105
+ def after_sign_up_path_for(resource)
106
+ after_sign_in_path_for(resource) if is_navigational_format?
107
+ end
108
+
109
+ # The path used after sign up for inactive accounts. You need to overwrite
110
+ # this method in your own RegistrationsController.
111
+ def after_inactive_sign_up_path_for(resource)
112
+ scope = Devise::Mapping.find_scope!(resource)
113
+ router_name = Devise.mappings[scope].router_name
114
+ context = router_name ? send(router_name) : self
115
+ context.respond_to?(:root_path) ? context.root_path : "/"
116
+ end
117
+
118
+ # The default url to be used after updating a resource. You need to overwrite
119
+ # this method in your own RegistrationsController.
120
+ def after_update_path_for(resource)
121
+ sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)
122
+ end
123
+
124
+ # Authenticates the current scope and gets the current resource from the session.
125
+ def authenticate_scope!
126
+ send(:"authenticate_#{resource_name}!", force: true)
127
+ self.resource = send(:"current_#{resource_name}")
128
+ end
129
+
130
+ # Check if the user should be signed in automatically after updating the password.
131
+ def sign_in_after_change_password?
132
+ return true if account_update_params[:password].blank?
133
+
134
+ resource_class.sign_in_after_change_password
135
+ end
136
+
137
+ def sign_up_params
138
+ devise_parameter_sanitizer.sanitize(:sign_up)
139
+ end
140
+
141
+ def account_update_params
142
+ devise_parameter_sanitizer.sanitize(:account_update)
143
+ end
144
+
145
+ def translation_scope
146
+ 'devise.registrations'
147
+ end
148
+
149
+ private
150
+
151
+ def set_flash_message_for_update(resource, prev_unconfirmed_email)
152
+ return unless is_flashing_format?
153
+
154
+ flash_key = if update_needs_confirmation?(resource, prev_unconfirmed_email)
155
+ :update_needs_confirmation
156
+ elsif sign_in_after_change_password?
157
+ :updated
158
+ else
159
+ :updated_but_not_signed_in
160
+ end
161
+ set_flash_message :notice, flash_key
162
+ end
163
+
164
+ def update_needs_confirmation?(resource, previous)
165
+ resource.respond_to?(:pending_reconfirmation?) &&
166
+ resource.pending_reconfirmation? &&
167
+ previous != resource.unconfirmed_email
168
+ end
169
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::SessionsController < DeviseController
4
+ prepend_before_action :require_no_authentication, only: [:new, :create]
5
+ prepend_before_action :allow_params_authentication!, only: :create
6
+ prepend_before_action :verify_signed_out_user, only: :destroy
7
+ prepend_before_action(only: [:create, :destroy]) { request.env["devise.skip_timeout"] = true }
8
+
9
+ # GET /resource/sign_in
10
+ def new
11
+ self.resource = resource_class.new(sign_in_params)
12
+ clean_up_passwords(resource)
13
+ yield resource if block_given?
14
+ respond_with(resource, serialize_options(resource))
15
+ end
16
+
17
+ # POST /resource/sign_in
18
+ def create
19
+ self.resource = warden.authenticate!(auth_options)
20
+ set_flash_message!(:notice, :signed_in)
21
+ sign_in(resource_name, resource)
22
+ yield resource if block_given?
23
+ respond_with resource, location: after_sign_in_path_for(resource)
24
+ end
25
+
26
+ # DELETE /resource/sign_out
27
+ def destroy
28
+ signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
29
+ set_flash_message! :notice, :signed_out if signed_out
30
+ yield if block_given?
31
+ respond_to_on_destroy(non_navigational_status: :no_content)
32
+ end
33
+
34
+ protected
35
+
36
+ def sign_in_params
37
+ devise_parameter_sanitizer.sanitize(:sign_in)
38
+ end
39
+
40
+ def serialize_options(resource)
41
+ methods = resource_class.authentication_keys.dup
42
+ methods = methods.keys if methods.is_a?(Hash)
43
+ methods << :password if resource.respond_to?(:password)
44
+ { methods: methods, only: [:password] }
45
+ end
46
+
47
+ def auth_options
48
+ { scope: resource_name, recall: "#{controller_path}#new", locale: I18n.locale }
49
+ end
50
+
51
+ def translation_scope
52
+ 'devise.sessions'
53
+ end
54
+
55
+ private
56
+
57
+ # Check if there is no signed in user before doing the sign out.
58
+ #
59
+ # If there is no signed in user, it will set the flash message and redirect
60
+ # to the after_sign_out path.
61
+ def verify_signed_out_user
62
+ if all_signed_out?
63
+ set_flash_message! :notice, :already_signed_out
64
+
65
+ respond_to_on_destroy(non_navigational_status: :unauthorized)
66
+ end
67
+ end
68
+
69
+ def all_signed_out?
70
+ users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
71
+
72
+ users.all?(&:blank?)
73
+ end
74
+
75
+ def respond_to_on_destroy(non_navigational_status: :no_content)
76
+ # We actually need to hardcode this as Rails default responder doesn't
77
+ # support returning empty response on GET request
78
+ respond_to do |format|
79
+ format.all { head non_navigational_status }
80
+ format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Devise::UnlocksController < DeviseController
4
+ prepend_before_action :require_no_authentication
5
+
6
+ # GET /resource/unlock/new
7
+ def new
8
+ self.resource = resource_class.new
9
+ end
10
+
11
+ # POST /resource/unlock
12
+ def create
13
+ self.resource = resource_class.send_unlock_instructions(resource_params)
14
+ yield resource if block_given?
15
+
16
+ if successfully_sent?(resource)
17
+ respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
18
+ else
19
+ respond_with(resource)
20
+ end
21
+ end
22
+
23
+ # GET /resource/unlock?unlock_token=abcdef
24
+ def show
25
+ self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
26
+ yield resource if block_given?
27
+
28
+ if resource.errors.empty?
29
+ set_flash_message! :notice, :unlocked
30
+ respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
31
+ else
32
+ # TODO: use `error_status` when the default changes to `:unprocessable_entity` / `:unprocessable_content`.
33
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ # The path used after sending unlock password instructions
40
+ def after_sending_unlock_instructions_path_for(resource)
41
+ new_session_path(resource) if is_navigational_format?
42
+ end
43
+
44
+ # The path used after unlocking the resource
45
+ def after_unlock_path_for(resource)
46
+ new_session_path(resource) if is_navigational_format?
47
+ end
48
+
49
+ def translation_scope
50
+ 'devise.unlocks'
51
+ end
52
+ end