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,533 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require 'active_support/core_ext/numeric/time'
5
+ require 'active_support/dependencies'
6
+ require 'orm_adapter'
7
+ require 'set'
8
+ require 'securerandom'
9
+ require 'responders'
10
+
11
+ module Devise
12
+ autoload :Delegator, 'devise/delegator'
13
+ autoload :Encryptor, 'devise/encryptor'
14
+ autoload :FailureApp, 'devise/failure_app'
15
+ autoload :OmniAuth, 'devise/omniauth'
16
+ autoload :Orm, 'devise/orm'
17
+ autoload :ParameterFilter, 'devise/parameter_filter'
18
+ autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
19
+ autoload :TimeInflector, 'devise/time_inflector'
20
+ autoload :TokenGenerator, 'devise/token_generator'
21
+
22
+ module Controllers
23
+ autoload :Helpers, 'devise/controllers/helpers'
24
+ autoload :Rememberable, 'devise/controllers/rememberable'
25
+ autoload :Responder, 'devise/controllers/responder'
26
+ autoload :ScopedViews, 'devise/controllers/scoped_views'
27
+ autoload :SignInOut, 'devise/controllers/sign_in_out'
28
+ autoload :StoreLocation, 'devise/controllers/store_location'
29
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
30
+ end
31
+
32
+ module Hooks
33
+ autoload :Proxy, 'devise/hooks/proxy'
34
+ end
35
+
36
+ module Mailers
37
+ autoload :Helpers, 'devise/mailers/helpers'
38
+ end
39
+
40
+ module Strategies
41
+ autoload :Base, 'devise/strategies/base'
42
+ autoload :Authenticatable, 'devise/strategies/authenticatable'
43
+ end
44
+
45
+ module Test
46
+ autoload :ControllerHelpers, 'devise/test/controller_helpers'
47
+ autoload :IntegrationHelpers, 'devise/test/integration_helpers'
48
+ end
49
+
50
+ # Constants which holds devise configuration for extensions. Those should
51
+ # not be modified by the "end user" (this is why they are constants).
52
+ ALL = []
53
+ CONTROLLERS = {}
54
+ ROUTES = {}
55
+ STRATEGIES = {}
56
+ URL_HELPERS = {}
57
+
58
+ # Strategies that do not require user input.
59
+ NO_INPUT = []
60
+
61
+ # True values used to check params
62
+ TRUE_VALUES = [true, 1, '1', 'on', 'ON', 't', 'T', 'true', 'TRUE']
63
+
64
+ # Secret key used by the key generator
65
+ mattr_accessor :secret_key
66
+ @@secret_key = nil
67
+
68
+ # Custom domain or key for cookies. Not set by default
69
+ mattr_accessor :rememberable_options
70
+ @@rememberable_options = {}
71
+
72
+ # The number of times to hash the password.
73
+ mattr_accessor :stretches
74
+ @@stretches = 12
75
+
76
+ # The default key used when authenticating over http auth.
77
+ mattr_accessor :http_authentication_key
78
+ @@http_authentication_key = nil
79
+
80
+ # Keys used when authenticating a user.
81
+ mattr_accessor :authentication_keys
82
+ @@authentication_keys = [:email]
83
+
84
+ # Request keys used when authenticating a user.
85
+ mattr_accessor :request_keys
86
+ @@request_keys = []
87
+
88
+ # Keys that should be case-insensitive.
89
+ mattr_accessor :case_insensitive_keys
90
+ @@case_insensitive_keys = [:email]
91
+
92
+ # Keys that should have whitespace stripped.
93
+ mattr_accessor :strip_whitespace_keys
94
+ @@strip_whitespace_keys = [:email]
95
+
96
+ # If http authentication is enabled by default.
97
+ mattr_accessor :http_authenticatable
98
+ @@http_authenticatable = false
99
+
100
+ # If http headers should be returned for ajax requests. True by default.
101
+ mattr_accessor :http_authenticatable_on_xhr
102
+ @@http_authenticatable_on_xhr = true
103
+
104
+ # If params authenticatable is enabled by default.
105
+ mattr_accessor :params_authenticatable
106
+ @@params_authenticatable = true
107
+
108
+ # The realm used in Http Basic Authentication.
109
+ mattr_accessor :http_authentication_realm
110
+ @@http_authentication_realm = "Application"
111
+
112
+ # Email regex used to validate email formats. It asserts that there are no
113
+ # @ symbols or whitespaces in either the localpart or the domain, and that
114
+ # there is a single @ symbol separating the localpart and the domain.
115
+ mattr_accessor :email_regexp
116
+ @@email_regexp = /\A[^@\s]+@[^@\s]+\z/
117
+
118
+ # Range validation for password length
119
+ mattr_accessor :password_length
120
+ @@password_length = 6..128
121
+
122
+ # The time the user will be remembered without asking for credentials again.
123
+ mattr_accessor :remember_for
124
+ @@remember_for = 2.weeks
125
+
126
+ # If true, extends the user's remember period when remembered via cookie.
127
+ mattr_accessor :extend_remember_period
128
+ @@extend_remember_period = false
129
+
130
+ # If true, all the remember me tokens are going to be invalidated when the user signs out.
131
+ mattr_accessor :expire_all_remember_me_on_sign_out
132
+ @@expire_all_remember_me_on_sign_out = true
133
+
134
+ # Time interval you can access your account before confirming your account.
135
+ # nil - allows unconfirmed access for unlimited time
136
+ mattr_accessor :allow_unconfirmed_access_for
137
+ @@allow_unconfirmed_access_for = 0.days
138
+
139
+ # Time interval the confirmation token is valid. nil = unlimited
140
+ mattr_accessor :confirm_within
141
+ @@confirm_within = nil
142
+
143
+ # Defines which key will be used when confirming an account.
144
+ mattr_accessor :confirmation_keys
145
+ @@confirmation_keys = [:email]
146
+
147
+ # Defines if email should be reconfirmable.
148
+ mattr_accessor :reconfirmable
149
+ @@reconfirmable = true
150
+
151
+ # Time interval to timeout the user session without activity.
152
+ mattr_accessor :timeout_in
153
+ @@timeout_in = 30.minutes
154
+
155
+ # Used to hash the password. Please generate one with rails secret.
156
+ mattr_accessor :pepper
157
+ @@pepper = nil
158
+
159
+ # Used to send notification to the original user email when their email is changed.
160
+ mattr_accessor :send_email_changed_notification
161
+ @@send_email_changed_notification = false
162
+
163
+ # Used to enable sending notification to user when their password is changed.
164
+ mattr_accessor :send_password_change_notification
165
+ @@send_password_change_notification = false
166
+
167
+ # Scoped views. Since it relies on fallbacks to render default views, it's
168
+ # turned off by default.
169
+ mattr_accessor :scoped_views
170
+ @@scoped_views = false
171
+
172
+ # Defines which strategy can be used to lock an account.
173
+ # Values: :failed_attempts, :none
174
+ mattr_accessor :lock_strategy
175
+ @@lock_strategy = :failed_attempts
176
+
177
+ # Defines which key will be used when locking and unlocking an account
178
+ mattr_accessor :unlock_keys
179
+ @@unlock_keys = [:email]
180
+
181
+ # Defines which strategy can be used to unlock an account.
182
+ # Values: :email, :time, :both
183
+ mattr_accessor :unlock_strategy
184
+ @@unlock_strategy = :both
185
+
186
+ # Number of authentication tries before locking an account
187
+ mattr_accessor :maximum_attempts
188
+ @@maximum_attempts = 20
189
+
190
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
191
+ mattr_accessor :unlock_in
192
+ @@unlock_in = 1.hour
193
+
194
+ # Defines which key will be used when recovering the password for an account
195
+ mattr_accessor :reset_password_keys
196
+ @@reset_password_keys = [:email]
197
+
198
+ # Time interval you can reset your password with a reset password key
199
+ mattr_accessor :reset_password_within
200
+ @@reset_password_within = 6.hours
201
+
202
+ # When set to false, resetting a password does not automatically sign in a user
203
+ mattr_accessor :sign_in_after_reset_password
204
+ @@sign_in_after_reset_password = true
205
+
206
+ # The default scope which is used by warden.
207
+ mattr_accessor :default_scope
208
+ @@default_scope = nil
209
+
210
+ # Address which sends Devise e-mails.
211
+ mattr_accessor :mailer_sender
212
+ @@mailer_sender = nil
213
+
214
+ # Skip session storage for the following strategies
215
+ mattr_accessor :skip_session_storage
216
+ @@skip_session_storage = [:http_auth]
217
+
218
+ # Which formats should be treated as navigational.
219
+ mattr_accessor :navigational_formats
220
+ @@navigational_formats = ["*/*", :html, :turbo_stream]
221
+
222
+ # The default responder used by Devise, used to customize status codes with:
223
+ #
224
+ # `config.responder.error_status`
225
+ # `config.responder.redirect_status`
226
+ #
227
+ # Can be replaced by a custom application responder.
228
+ mattr_accessor :responder
229
+ @@responder = Devise::Controllers::Responder
230
+
231
+ # When set to true, signing out a user signs out all other scopes.
232
+ mattr_accessor :sign_out_all_scopes
233
+ @@sign_out_all_scopes = true
234
+
235
+ # The default method used while signing out
236
+ mattr_accessor :sign_out_via
237
+ @@sign_out_via = :delete
238
+
239
+ # The parent controller all Devise controllers inherits from.
240
+ # Defaults to ApplicationController. This should be set early
241
+ # in the initialization process and should be set to a string.
242
+ mattr_accessor :parent_controller
243
+ @@parent_controller = "ApplicationController"
244
+
245
+ # The parent mailer all Devise mailers inherit from.
246
+ # Defaults to ActionMailer::Base. This should be set early
247
+ # in the initialization process and should be set to a string.
248
+ mattr_accessor :parent_mailer
249
+ @@parent_mailer = "ActionMailer::Base"
250
+
251
+ # The router Devise should use to generate routes. Defaults
252
+ # to :main_app. Should be overridden by engines in order
253
+ # to provide custom routes.
254
+ mattr_accessor :router_name
255
+ @@router_name = nil
256
+
257
+ # Set the OmniAuth path prefix so it can be overridden when
258
+ # Devise is used in a mountable engine
259
+ mattr_accessor :omniauth_path_prefix
260
+ @@omniauth_path_prefix = nil
261
+
262
+ # Set if we should clean up the CSRF Token on authentication
263
+ mattr_accessor :clean_up_csrf_token_on_authentication
264
+ @@clean_up_csrf_token_on_authentication = true
265
+
266
+ # When false, Devise will not attempt to reload routes on eager load.
267
+ # This can reduce the time taken to boot the app but if your application
268
+ # requires the Devise mappings to be loaded during boot time the application
269
+ # won't boot properly.
270
+ mattr_accessor :reload_routes
271
+ @@reload_routes = true
272
+
273
+ # PRIVATE CONFIGURATION
274
+
275
+ # Store scopes mappings.
276
+ @@mappings = {}
277
+ def self.mappings
278
+ # Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.
279
+ # However, Devise's mappings are built during the routes loading phase.
280
+ # To ensure it works correctly, we need to load the routes first before accessing @@mappings.
281
+ Rails.application.try(:reload_routes_unless_loaded)
282
+ @@mappings
283
+ end
284
+
285
+ # OmniAuth configurations.
286
+ mattr_reader :omniauth_configs
287
+ @@omniauth_configs = {}
288
+
289
+ # Define a set of modules that are called when a mapping is added.
290
+ mattr_reader :helpers
291
+ @@helpers = Set.new
292
+ @@helpers << Devise::Controllers::Helpers
293
+
294
+ # Private methods to interface with Warden.
295
+ mattr_accessor :warden_config
296
+ @@warden_config = nil
297
+ @@warden_config_blocks = []
298
+
299
+ # When true, enter in paranoid mode to avoid user enumeration.
300
+ mattr_accessor :paranoid
301
+ @@paranoid = false
302
+
303
+ # When true, warn user if they just used next-to-last attempt of authentication
304
+ mattr_accessor :last_attempt_warning
305
+ @@last_attempt_warning = true
306
+
307
+ # Stores the token generator
308
+ mattr_accessor :token_generator
309
+ @@token_generator = nil
310
+
311
+ # When set to false, changing a password does not automatically sign in a user
312
+ mattr_accessor :sign_in_after_change_password
313
+ @@sign_in_after_change_password = true
314
+
315
+ # Default way to set up Devise. Run rails generate devise_install to create
316
+ # a fresh initializer with all configuration values.
317
+ def self.setup
318
+ yield self
319
+ end
320
+
321
+ class Getter
322
+ def initialize(name)
323
+ @name = name
324
+ end
325
+
326
+ def get
327
+ # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.
328
+ if ActiveSupport::Dependencies.respond_to?(:constantize)
329
+ ActiveSupport::Dependencies.constantize(@name)
330
+ else
331
+ @name.constantize
332
+ end
333
+ end
334
+ end
335
+
336
+ def self.ref(arg)
337
+ # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.
338
+ if ActiveSupport::Dependencies.respond_to?(:reference)
339
+ ActiveSupport::Dependencies.reference(arg)
340
+ end
341
+ Getter.new(arg)
342
+ end
343
+
344
+ def self.available_router_name
345
+ router_name || :main_app
346
+ end
347
+
348
+ def self.omniauth_providers
349
+ omniauth_configs.keys
350
+ end
351
+
352
+ # Get the mailer class from the mailer reference object.
353
+ def self.mailer
354
+ @@mailer_ref.get
355
+ end
356
+
357
+ # Set the mailer reference object to access the mailer.
358
+ def self.mailer=(class_name)
359
+ @@mailer_ref = ref(class_name)
360
+ end
361
+ self.mailer = "Devise::Mailer"
362
+
363
+ # Small method that adds a mapping to Devise.
364
+ def self.add_mapping(resource, options)
365
+ mapping = Devise::Mapping.new(resource, options)
366
+ @@mappings[mapping.name] = mapping
367
+ @@default_scope ||= mapping.name
368
+ @@helpers.each { |h| h.define_helpers(mapping) }
369
+ mapping
370
+ end
371
+
372
+ # Register available devise modules. For the standard modules that Devise provides, this method is
373
+ # called from lib/devise/modules.rb. Third-party modules need to be added explicitly using this method.
374
+ #
375
+ # Note that adding a module using this method does not cause it to be used in the authentication
376
+ # process. That requires that the module be listed in the arguments passed to the 'devise' method
377
+ # in the model class definition.
378
+ #
379
+ # == Options:
380
+ #
381
+ # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
382
+ # +controller+ - Symbol representing the name of an existing or custom *controller* for this module.
383
+ # +route+ - Symbol representing the named *route* helper for this module.
384
+ # +strategy+ - Symbol representing if this module got a custom *strategy*.
385
+ # +insert_at+ - Integer representing the order in which this module's model will be included
386
+ #
387
+ # All values, except :model, accept also a boolean and will have the same name as the given module
388
+ # name.
389
+ #
390
+ # == Examples:
391
+ #
392
+ # Devise.add_module(:party_module)
393
+ # Devise.add_module(:party_module, strategy: true, controller: :sessions)
394
+ # Devise.add_module(:party_module, model: 'party_module/model')
395
+ # Devise.add_module(:party_module, insert_at: 0)
396
+ #
397
+ def self.add_module(module_name, options = {})
398
+ options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input, :insert_at)
399
+
400
+ ALL.insert (options[:insert_at] || -1), module_name
401
+
402
+ if strategy = options[:strategy]
403
+ strategy = (strategy == true ? module_name : strategy)
404
+ STRATEGIES[module_name] = strategy
405
+ end
406
+
407
+ if controller = options[:controller]
408
+ controller = (controller == true ? module_name : controller)
409
+ CONTROLLERS[module_name] = controller
410
+ end
411
+
412
+ NO_INPUT << strategy if options[:no_input]
413
+
414
+ if route = options[:route]
415
+ case route
416
+ when TrueClass
417
+ key, value = module_name, []
418
+ when Symbol
419
+ key, value = route, []
420
+ when Hash
421
+ key, value = route.keys.first, route.values.flatten
422
+ else
423
+ raise ArgumentError, ":route should be true, a Symbol or a Hash"
424
+ end
425
+
426
+ URL_HELPERS[key] ||= []
427
+ URL_HELPERS[key].concat(value)
428
+ URL_HELPERS[key].uniq!
429
+
430
+ ROUTES[module_name] = key
431
+ end
432
+
433
+ if options[:model]
434
+ path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
435
+ camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
436
+ Devise::Models.send(:autoload, camelized.to_sym, path)
437
+ end
438
+
439
+ Devise::Mapping.add_module module_name
440
+ end
441
+
442
+ # Sets warden configuration using a block that will be invoked on warden
443
+ # initialization.
444
+ #
445
+ # Devise.setup do |config|
446
+ # config.allow_unconfirmed_access_for = 2.days
447
+ #
448
+ # config.warden do |warden_config|
449
+ # # Configure warden to use other strategies, like oauth.
450
+ # warden_config.oauth(:twitter)
451
+ # end
452
+ # end
453
+ def self.warden(&block)
454
+ @@warden_config_blocks << block
455
+ end
456
+
457
+ # Specify an OmniAuth provider.
458
+ #
459
+ # config.omniauth :github, APP_ID, APP_SECRET
460
+ #
461
+ def self.omniauth(provider, *args)
462
+ config = Devise::OmniAuth::Config.new(provider, args)
463
+ @@omniauth_configs[config.strategy_name.to_sym] = config
464
+ end
465
+
466
+ # Include helpers in the given scope to AC and AV.
467
+ def self.include_helpers(scope)
468
+ ActiveSupport.on_load(:action_controller) do
469
+ include scope::Helpers if defined?(scope::Helpers)
470
+ include scope::UrlHelpers
471
+ end
472
+
473
+ ActiveSupport.on_load(:action_view) do
474
+ include scope::UrlHelpers
475
+ end
476
+ end
477
+
478
+ # Regenerates url helpers considering Devise.mapping
479
+ def self.regenerate_helpers!
480
+ Devise::Controllers::UrlHelpers.remove_helpers!
481
+ Devise::Controllers::UrlHelpers.generate_helpers!
482
+ end
483
+
484
+ # A method used internally to complete the setup of warden manager after routes are loaded.
485
+ # See lib/devise/rails/routes.rb - ActionDispatch::Routing::RouteSet#finalize_with_devise!
486
+ def self.configure_warden! #:nodoc:
487
+ @@warden_configured ||= begin
488
+ warden_config.failure_app = Devise::Delegator.new
489
+ warden_config.default_scope = Devise.default_scope
490
+ warden_config.intercept_401 = false
491
+
492
+ Devise.mappings.each_value do |mapping|
493
+ warden_config.scope_defaults mapping.name, strategies: mapping.strategies
494
+
495
+ warden_config.serialize_into_session(mapping.name) do |record|
496
+ mapping.to.serialize_into_session(record)
497
+ end
498
+
499
+ warden_config.serialize_from_session(mapping.name) do |args|
500
+ mapping.to.serialize_from_session(*args)
501
+ end
502
+ end
503
+
504
+ @@warden_config_blocks.map { |block| block.call Devise.warden_config }
505
+ true
506
+ end
507
+ end
508
+
509
+ # Generate a friendly string randomly to be used as token.
510
+ # By default, length is 20 characters.
511
+ def self.friendly_token(length = 20)
512
+ # To calculate real characters, we must perform this operation.
513
+ # See SecureRandom.urlsafe_base64
514
+ rlength = (length * 3) / 4
515
+ SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz')
516
+ end
517
+
518
+ # constant-time comparison algorithm to prevent timing attacks
519
+ def self.secure_compare(a, b)
520
+ return false if a.nil? || b.nil?
521
+ ActiveSupport::SecurityUtils.secure_compare(a, b)
522
+ end
523
+
524
+ def self.deprecator
525
+ @deprecator ||= ActiveSupport::Deprecation.new("5.0", "Devise")
526
+ end
527
+ end
528
+
529
+ require 'warden'
530
+ require 'devise/mapping'
531
+ require 'devise/models'
532
+ require 'devise/modules'
533
+ require 'devise/rails'
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/active_record'
4
+ require 'generators/devise/orm_helpers'
5
+
6
+ module ActiveRecord
7
+ module Generators
8
+ class DeviseGenerator < Base
9
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
10
+
11
+ class_option :primary_key_type, type: :string, desc: "The type for primary key"
12
+
13
+ include Devise::Generators::OrmHelpers
14
+ source_root File.expand_path("../templates", __FILE__)
15
+
16
+ def copy_devise_migration
17
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
18
+ migration_template "migration_existing.rb", "#{migration_path}/add_devise_to_#{table_name}.rb", migration_version: migration_version
19
+ else
20
+ migration_template "migration.rb", "#{migration_path}/devise_create_#{table_name}.rb", migration_version: migration_version
21
+ end
22
+ end
23
+
24
+ def generate_model
25
+ invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
26
+ end
27
+
28
+ def inject_devise_content
29
+ content = model_contents
30
+
31
+ class_path = if namespaced?
32
+ class_name.to_s.split("::")
33
+ else
34
+ [class_name]
35
+ end
36
+
37
+ indent_depth = class_path.size - 1
38
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
39
+
40
+ inject_into_class(model_path, class_path.last, content) if model_exists?
41
+ end
42
+
43
+ def migration_data
44
+ <<RUBY
45
+ ## Database authenticatable
46
+ t.string :email, null: false, default: ""
47
+ t.string :encrypted_password, null: false, default: ""
48
+
49
+ ## Recoverable
50
+ t.string :reset_password_token
51
+ t.datetime :reset_password_sent_at
52
+
53
+ ## Rememberable
54
+ t.datetime :remember_created_at
55
+
56
+ ## Trackable
57
+ # t.integer :sign_in_count, default: 0, null: false
58
+ # t.datetime :current_sign_in_at
59
+ # t.datetime :last_sign_in_at
60
+ # t.#{ip_column} :current_sign_in_ip
61
+ # t.#{ip_column} :last_sign_in_ip
62
+
63
+ ## Confirmable
64
+ # t.string :confirmation_token
65
+ # t.datetime :confirmed_at
66
+ # t.datetime :confirmation_sent_at
67
+ # t.string :unconfirmed_email # Only if using reconfirmable
68
+
69
+ ## Lockable
70
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
71
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
72
+ # t.datetime :locked_at
73
+ RUBY
74
+ end
75
+
76
+ def ip_column
77
+ # Padded with spaces so it aligns nicely with the rest of the columns.
78
+ "%-8s" % (inet? ? "inet" : "string")
79
+ end
80
+
81
+ def inet?
82
+ postgresql?
83
+ end
84
+
85
+ def rails61_and_up?
86
+ Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)
87
+ end
88
+
89
+ def postgresql?
90
+ ar_config && ar_config['adapter'] == 'postgresql'
91
+ end
92
+
93
+ def ar_config
94
+ if ActiveRecord::Base.configurations.respond_to?(:configs_for)
95
+ if rails61_and_up?
96
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").configuration_hash
97
+ else
98
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: "primary").config
99
+ end
100
+ else
101
+ ActiveRecord::Base.configurations[Rails.env]
102
+ end
103
+ end
104
+
105
+ def migration_version
106
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
107
+ end
108
+
109
+ def primary_key_type
110
+ primary_key_string
111
+ end
112
+
113
+ def primary_key_string
114
+ key_string = options[:primary_key_type]
115
+ ", id: :#{key_string}" if key_string
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ create_table :<%= table_name %><%= primary_key_type %> do |t|
6
+ <%= migration_data -%>
7
+
8
+ <% attributes.each do |attribute| -%>
9
+ t.<%= attribute.type %> :<%= attribute.name %>
10
+ <% end -%>
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_index :<%= table_name %>, :email, unique: true
16
+ add_index :<%= table_name %>, :reset_password_token, unique: true
17
+ # add_index :<%= table_name %>, :confirmation_token, unique: true
18
+ # add_index :<%= table_name %>, :unlock_token, unique: true
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
4
+ def self.up
5
+ change_table :<%= table_name %> do |t|
6
+ <%= migration_data -%>
7
+
8
+ <% attributes.each do |attribute| -%>
9
+ t.<%= attribute.type %> :<%= attribute.name %>
10
+ <% end -%>
11
+
12
+ # Uncomment below if timestamps were not included in your original model.
13
+ # t.timestamps null: false
14
+ end
15
+
16
+ add_index :<%= table_name %>, :email, unique: true
17
+ add_index :<%= table_name %>, :reset_password_token, unique: true
18
+ # add_index :<%= table_name %>, :confirmation_token, unique: true
19
+ # add_index :<%= table_name %>, :unlock_token, unique: true
20
+ end
21
+
22
+ def self.down
23
+ # By default, we don't want to make any assumption about how to roll back a migration when your
24
+ # model already existed. Please edit below which fields you would like to remove in this migration.
25
+ raise ActiveRecord::IrreversibleMigration
26
+ end
27
+ end