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,514 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/try"
4
+ require "active_support/core_ext/hash/slice"
5
+
6
+ module Devise
7
+ module RouteSet
8
+ def finalize!
9
+ result = super
10
+ @devise_finalized ||= begin
11
+ if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
12
+ warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
13
+ "In this case, you probably want to set Devise.router_name = MOUNT_POINT, where " \
14
+ "MOUNT_POINT is a symbol representing where this engine will be mounted at. For " \
15
+ "now Devise will default the mount point to :main_app. You can explicitly set it" \
16
+ " to :main_app as well in case you want to keep the current behavior."
17
+ end
18
+
19
+ Devise.configure_warden!
20
+ Devise.regenerate_helpers!
21
+ true
22
+ end
23
+ result
24
+ end
25
+ end
26
+ end
27
+
28
+ module ActionDispatch::Routing
29
+ class RouteSet #:nodoc:
30
+ # Ensure Devise modules are included only after loading routes, because we
31
+ # need devise_for mappings already declared to create filters and helpers.
32
+ prepend Devise::RouteSet
33
+ end
34
+
35
+ class Mapper
36
+ # Includes devise_for method for routes. This method is responsible to
37
+ # generate all needed routes for devise, based on what modules you have
38
+ # defined in your model.
39
+ #
40
+ # ==== Examples
41
+ #
42
+ # Let's say you have an User model configured to use authenticatable,
43
+ # confirmable and recoverable modules. After creating this inside your routes:
44
+ #
45
+ # devise_for :users
46
+ #
47
+ # This method is going to look inside your User model and create the
48
+ # needed routes:
49
+ #
50
+ # # Session routes for Authenticatable (default)
51
+ # new_user_session GET /users/sign_in {controller:"devise/sessions", action:"new"}
52
+ # user_session POST /users/sign_in {controller:"devise/sessions", action:"create"}
53
+ # destroy_user_session DELETE /users/sign_out {controller:"devise/sessions", action:"destroy"}
54
+ #
55
+ # # Password routes for Recoverable, if User model has :recoverable configured
56
+ # new_user_password GET /users/password/new(.:format) {controller:"devise/passwords", action:"new"}
57
+ # edit_user_password GET /users/password/edit(.:format) {controller:"devise/passwords", action:"edit"}
58
+ # user_password PUT /users/password(.:format) {controller:"devise/passwords", action:"update"}
59
+ # POST /users/password(.:format) {controller:"devise/passwords", action:"create"}
60
+ #
61
+ # # Confirmation routes for Confirmable, if User model has :confirmable configured
62
+ # new_user_confirmation GET /users/confirmation/new(.:format) {controller:"devise/confirmations", action:"new"}
63
+ # user_confirmation GET /users/confirmation(.:format) {controller:"devise/confirmations", action:"show"}
64
+ # POST /users/confirmation(.:format) {controller:"devise/confirmations", action:"create"}
65
+ #
66
+ # ==== Routes integration
67
+ #
68
+ # +devise_for+ is meant to play nicely with other routes methods. For example,
69
+ # by calling +devise_for+ inside a namespace, it automatically nests your devise
70
+ # controllers:
71
+ #
72
+ # namespace :publisher do
73
+ # devise_for :account
74
+ # end
75
+ #
76
+ # The snippet above will use publisher/sessions controller instead of devise/sessions
77
+ # controller. You can revert this change or configure it directly by passing the :module
78
+ # option described below to +devise_for+.
79
+ #
80
+ # Also note that when you use a namespace it will affect all the helpers and methods
81
+ # for controllers and views. For example, using the above setup you'll end with
82
+ # following methods: current_publisher_account, authenticate_publisher_account!,
83
+ # publisher_account_signed_in, etc.
84
+ #
85
+ # The only aspect not affect by the router configuration is the model name. The
86
+ # model name can be explicitly set via the :class_name option.
87
+ #
88
+ # ==== Options
89
+ #
90
+ # You can configure your routes with some options:
91
+ #
92
+ # * class_name: set up a different class to be looked up by devise, if it cannot be
93
+ # properly found by the route name.
94
+ #
95
+ # devise_for :users, class_name: 'Account'
96
+ #
97
+ # * path: allows you to set up path name that will be used, as rails routes does.
98
+ # The following route configuration would set up your route as /accounts instead of /users:
99
+ #
100
+ # devise_for :users, path: 'accounts'
101
+ #
102
+ # * singular: set up the singular name for the given resource. This is used as the helper methods
103
+ # names in controller ("authenticate_#{singular}!", "#{singular}_signed_in?", "current_#{singular}"
104
+ # and "#{singular}_session"), as the scope name in routes and as the scope given to warden.
105
+ #
106
+ # devise_for :admins, singular: :manager
107
+ #
108
+ # devise_scope :manager do
109
+ # ...
110
+ # end
111
+ #
112
+ # class ManagerController < ApplicationController
113
+ # before_action authenticate_manager!
114
+ #
115
+ # def show
116
+ # @manager = current_manager
117
+ # ...
118
+ # end
119
+ # end
120
+ #
121
+ # * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
122
+ # :password, :confirmation, :unlock.
123
+ #
124
+ # devise_for :users, path_names: {
125
+ # sign_in: 'login', sign_out: 'logout',
126
+ # password: 'secret', confirmation: 'verification',
127
+ # registration: 'register', edit: 'edit/profile'
128
+ # }
129
+ #
130
+ # * controllers: the controller which should be used. All routes by default points to Devise controllers.
131
+ # However, if you want them to point to custom controller, you should do:
132
+ #
133
+ # devise_for :users, controllers: { sessions: "users/sessions" }
134
+ #
135
+ # * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given
136
+ # are also allowed as parameter.
137
+ #
138
+ # * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :delete),
139
+ # if you wish to restrict this to accept only :post or :delete requests you should do:
140
+ #
141
+ # devise_for :users, sign_out_via: [:get, :post]
142
+ #
143
+ # You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
144
+ #
145
+ # * module: the namespace to find controllers (default: "devise", thus
146
+ # accessing devise/sessions, devise/registrations, and so on). If you want
147
+ # to namespace all at once, use module:
148
+ #
149
+ # devise_for :users, module: "users"
150
+ #
151
+ # * skip: tell which controller you want to skip routes from being created.
152
+ # It accepts :all as an option, meaning it will not generate any route at all:
153
+ #
154
+ # devise_for :users, skip: :sessions
155
+ #
156
+ # * only: the opposite of :skip, tell which controllers only to generate routes to:
157
+ #
158
+ # devise_for :users, only: :sessions
159
+ #
160
+ # * skip_helpers: skip generating Devise url helpers like new_session_path(@user).
161
+ # This is useful to avoid conflicts with previous routes and is false by default.
162
+ # It accepts true as option, meaning it will skip all the helpers for the controllers
163
+ # given in :skip but it also accepts specific helpers to be skipped:
164
+ #
165
+ # devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true
166
+ # devise_for :users, skip_helpers: [:registrations, :confirmations]
167
+ #
168
+ # * format: include "(.:format)" in the generated routes? true by default, set to false to disable:
169
+ #
170
+ # devise_for :users, format: false
171
+ #
172
+ # * constraints: works the same as Rails' constraints
173
+ #
174
+ # * defaults: works the same as Rails' defaults
175
+ #
176
+ # * router_name: allows application level router name to be overwritten for the current scope
177
+ #
178
+ # ==== Scoping
179
+ #
180
+ # Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
181
+ #
182
+ # scope "/my" do
183
+ # devise_for :users
184
+ # end
185
+ #
186
+ # However, since Devise uses the request path to retrieve the current user,
187
+ # this has one caveat: If you are using a dynamic segment, like so ...
188
+ #
189
+ # scope ":locale" do
190
+ # devise_for :users
191
+ # end
192
+ #
193
+ # you are required to configure default_url_options in your
194
+ # ApplicationController class, so Devise can pick it:
195
+ #
196
+ # class ApplicationController < ActionController::Base
197
+ # def self.default_url_options
198
+ # { locale: I18n.locale }
199
+ # end
200
+ # end
201
+ #
202
+ # ==== Adding custom actions to override controllers
203
+ #
204
+ # You can pass a block to devise_for that will add any routes defined in the block to Devise's
205
+ # list of known actions. This is important if you add a custom action to a controller that
206
+ # overrides an out of the box Devise controller.
207
+ # For example:
208
+ #
209
+ # class RegistrationsController < Devise::RegistrationsController
210
+ # def update
211
+ # # do something different here
212
+ # end
213
+ #
214
+ # def deactivate
215
+ # # not a standard action
216
+ # # deactivate code here
217
+ # end
218
+ # end
219
+ #
220
+ # In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
221
+ #
222
+ # devise_scope :owner do
223
+ # post "deactivate", to: "registrations#deactivate", as: "deactivate_registration"
224
+ # end
225
+ #
226
+ def devise_for(*resources)
227
+ @devise_finalized = false
228
+ raise_no_secret_key unless Devise.secret_key
229
+ options = resources.extract_options!
230
+
231
+ options[:as] ||= @scope[:as] if @scope[:as].present?
232
+ options[:module] ||= @scope[:module] if @scope[:module].present?
233
+ options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
234
+ options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
235
+ options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
236
+ options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
237
+ options[:options] = @scope[:options] || {}
238
+
239
+ resources.map!(&:to_sym)
240
+
241
+ resources.each do |resource|
242
+ mapping = Devise.add_mapping(resource, options)
243
+
244
+ begin
245
+ raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
246
+ rescue NameError => e
247
+ raise unless mapping.class_name == resource.to_s.classify
248
+ warn "[WARNING] You provided devise_for #{resource.inspect} but there is " \
249
+ "no model #{mapping.class_name} defined in your application"
250
+ next
251
+ rescue NoMethodError => e
252
+ raise unless e.message.include?("undefined method `devise'")
253
+ raise_no_devise_method_error!(mapping.class_name)
254
+ end
255
+
256
+ if options[:controllers] && options[:controllers][:omniauth_callbacks]
257
+ unless mapping.omniauthable?
258
+ raise ArgumentError, "Mapping omniauth_callbacks on a resource that is not omniauthable\n" \
259
+ "Please add `devise :omniauthable` to the `#{mapping.class_name}` model"
260
+ end
261
+ end
262
+
263
+ routes = mapping.used_routes
264
+
265
+ devise_scope mapping.name do
266
+ with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
267
+ routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
268
+ end
269
+ end
270
+ end
271
+ end
272
+
273
+ # Allow you to add authentication request from the router.
274
+ # Takes an optional scope and block to provide constraints
275
+ # on the model instance itself.
276
+ #
277
+ # authenticate do
278
+ # resources :post
279
+ # end
280
+ #
281
+ # authenticate(:admin) do
282
+ # resources :users
283
+ # end
284
+ #
285
+ # authenticate :user, lambda {|u| u.role == "admin"} do
286
+ # root to: "admin/dashboard#show", as: :user_root
287
+ # end
288
+ #
289
+ def authenticate(scope = nil, block = nil)
290
+ constraints_for(:authenticate!, scope, block) do
291
+ yield
292
+ end
293
+ end
294
+
295
+ # Allow you to route based on whether a scope is authenticated. You
296
+ # can optionally specify which scope and a block. The block accepts
297
+ # a model and allows extra constraints to be done on the instance.
298
+ #
299
+ # authenticated :admin do
300
+ # root to: 'admin/dashboard#show', as: :admin_root
301
+ # end
302
+ #
303
+ # authenticated do
304
+ # root to: 'dashboard#show', as: :authenticated_root
305
+ # end
306
+ #
307
+ # authenticated :user, lambda {|u| u.role == "admin"} do
308
+ # root to: "admin/dashboard#show", as: :user_root
309
+ # end
310
+ #
311
+ # root to: 'landing#show'
312
+ #
313
+ def authenticated(scope = nil, block = nil)
314
+ constraints_for(:authenticate?, scope, block) do
315
+ yield
316
+ end
317
+ end
318
+
319
+ # Allow you to route based on whether a scope is *not* authenticated.
320
+ # You can optionally specify which scope.
321
+ #
322
+ # unauthenticated do
323
+ # as :user do
324
+ # root to: 'devise/registrations#new'
325
+ # end
326
+ # end
327
+ #
328
+ # root to: 'dashboard#show'
329
+ #
330
+ def unauthenticated(scope = nil)
331
+ constraint = lambda do |request|
332
+ not request.env["warden"].authenticate? scope: scope
333
+ end
334
+
335
+ constraints(constraint) do
336
+ yield
337
+ end
338
+ end
339
+
340
+ # Sets the devise scope to be used in the controller. If you have custom routes,
341
+ # you are required to call this method (also aliased as :as) in order to specify
342
+ # to which controller it is targeted.
343
+ #
344
+ # as :user do
345
+ # get "sign_in", to: "devise/sessions#new"
346
+ # end
347
+ #
348
+ # Notice you cannot have two scopes mapping to the same URL. And remember, if
349
+ # you try to access a devise controller without specifying a scope, it will
350
+ # raise ActionNotFound error.
351
+ #
352
+ # Also be aware of that 'devise_scope' and 'as' use the singular form of the
353
+ # noun where other devise route commands expect the plural form. This would be a
354
+ # good and working example.
355
+ #
356
+ # devise_scope :user do
357
+ # get "/some/route" => "some_devise_controller"
358
+ # end
359
+ # devise_for :users
360
+ #
361
+ # Notice and be aware of the differences above between :user and :users
362
+ def devise_scope(scope)
363
+ constraint = lambda do |request|
364
+ request.env["devise.mapping"] = Devise.mappings[scope]
365
+ true
366
+ end
367
+
368
+ constraints(constraint) do
369
+ yield
370
+ end
371
+ end
372
+ alias :as :devise_scope
373
+
374
+ protected
375
+
376
+ def devise_session(mapping, controllers) #:nodoc:
377
+ resource :session, only: [], controller: controllers[:sessions], path: "" do
378
+ get :new, path: mapping.path_names[:sign_in], as: "new"
379
+ post :create, path: mapping.path_names[:sign_in]
380
+ match :destroy, path: mapping.path_names[:sign_out], as: "destroy", via: mapping.sign_out_via
381
+ end
382
+ end
383
+
384
+ def devise_password(mapping, controllers) #:nodoc:
385
+ resource :password, only: [:new, :create, :edit, :update],
386
+ path: mapping.path_names[:password], controller: controllers[:passwords]
387
+ end
388
+
389
+ def devise_confirmation(mapping, controllers) #:nodoc:
390
+ resource :confirmation, only: [:new, :create, :show],
391
+ path: mapping.path_names[:confirmation], controller: controllers[:confirmations]
392
+ end
393
+
394
+ def devise_unlock(mapping, controllers) #:nodoc:
395
+ if mapping.to.unlock_strategy_enabled?(:email)
396
+ resource :unlock, only: [:new, :create, :show],
397
+ path: mapping.path_names[:unlock], controller: controllers[:unlocks]
398
+ end
399
+ end
400
+
401
+ def devise_registration(mapping, controllers) #:nodoc:
402
+ path_names = {
403
+ new: mapping.path_names[:sign_up],
404
+ edit: mapping.path_names[:edit],
405
+ cancel: mapping.path_names[:cancel]
406
+ }
407
+
408
+ options = {
409
+ only: [:new, :create, :edit, :update, :destroy],
410
+ path: mapping.path_names[:registration],
411
+ path_names: path_names,
412
+ controller: controllers[:registrations]
413
+ }
414
+
415
+ resource :registration, **options do
416
+ get :cancel
417
+ end
418
+ end
419
+
420
+ def devise_omniauth_callback(mapping, controllers) #:nodoc:
421
+ if mapping.fullpath =~ /:[a-zA-Z_]/
422
+ raise <<-ERROR
423
+ Devise does not support scoping OmniAuth callbacks under a dynamic segment
424
+ and you have set #{mapping.fullpath.inspect}. You can work around by passing
425
+ `skip: :omniauth_callbacks` to the `devise_for` call and extract omniauth
426
+ options to another `devise_for` call outside the scope. Here is an example:
427
+
428
+ devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}
429
+
430
+ scope '/(:locale)', locale: /ru|en/ do
431
+ devise_for :users, skip: :omniauth_callbacks
432
+ end
433
+ ERROR
434
+ end
435
+ current_scope = @scope.dup
436
+ if @scope.respond_to? :new
437
+ @scope = @scope.new path: nil
438
+ else
439
+ @scope[:path] = nil
440
+ end
441
+ path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")
442
+
443
+ set_omniauth_path_prefix!(path_prefix)
444
+
445
+ mapping.to.omniauth_providers.each do |provider|
446
+ match "#{path_prefix}/#{provider}",
447
+ to: "#{controllers[:omniauth_callbacks]}#passthru",
448
+ as: "#{provider}_omniauth_authorize",
449
+ via: OmniAuth.config.allowed_request_methods
450
+
451
+ match "#{path_prefix}/#{provider}/callback",
452
+ to: "#{controllers[:omniauth_callbacks]}##{provider}",
453
+ as: "#{provider}_omniauth_callback",
454
+ via: [:get, :post]
455
+ end
456
+ ensure
457
+ @scope = current_scope
458
+ end
459
+
460
+ def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
461
+ current_scope = @scope.dup
462
+
463
+ exclusive = { as: new_as, path: new_path, module: nil }
464
+ exclusive.merge!(options.slice(:constraints, :format, :defaults, :options))
465
+
466
+ if @scope.respond_to? :new
467
+ @scope = @scope.new exclusive
468
+ else
469
+ exclusive.each_pair { |key, value| @scope[key] = value }
470
+ end
471
+ yield
472
+ ensure
473
+ @scope = current_scope
474
+ end
475
+
476
+ def constraints_for(method_to_apply, scope = nil, block = nil)
477
+ constraint = lambda do |request|
478
+ request.env['warden'].send(method_to_apply, scope: scope) &&
479
+ (block.nil? || block.call(request.env["warden"].user(scope)))
480
+ end
481
+
482
+ constraints(constraint) do
483
+ yield
484
+ end
485
+ end
486
+
487
+ def set_omniauth_path_prefix!(path_prefix) #:nodoc:
488
+ if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix
489
+ raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \
490
+ "1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\n" \
491
+ "2) You are setting :omniauthable in more than one model\n" \
492
+ "3) You changed your Devise routes/OmniAuth setting and haven't restarted your server"
493
+ else
494
+ ::OmniAuth.config.path_prefix = path_prefix
495
+ end
496
+ end
497
+
498
+ def raise_no_secret_key #:nodoc:
499
+ raise <<-ERROR
500
+ Devise.secret_key was not set. Please add the following to your Devise initializer:
501
+
502
+ config.secret_key = '#{SecureRandom.hex(64)}'
503
+
504
+ Please ensure you restarted your application after installing Devise or setting the key.
505
+ ERROR
506
+ end
507
+
508
+ def raise_no_devise_method_error!(klass) #:nodoc:
509
+ raise "#{klass} does not respond to 'devise' method. This usually means you haven't " \
510
+ "loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " \
511
+ "inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
512
+ end
513
+ end
514
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Warden::Mixins::Common
4
+ def request
5
+ @request ||= ActionDispatch::Request.new(env)
6
+ end
7
+
8
+ def reset_session!
9
+ request.reset_session
10
+ end
11
+
12
+ def cookies
13
+ request.cookie_jar
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'devise/rails/routes'
4
+ require 'devise/rails/warden_compat'
5
+
6
+ module Devise
7
+ class Engine < ::Rails::Engine
8
+ config.devise = Devise
9
+
10
+ # Initialize Warden and copy its configurations.
11
+ config.app_middleware.use Warden::Manager do |config|
12
+ Devise.warden_config = config
13
+ end
14
+
15
+ # Force routes to be loaded if we are doing any eager load.
16
+ config.before_eager_load do |app|
17
+ app.reload_routes! if Devise.reload_routes
18
+ end
19
+
20
+ initializer "devise.deprecator" do |app|
21
+ app.deprecators[:devise] = Devise.deprecator if app.respond_to?(:deprecators)
22
+ end
23
+
24
+ initializer "devise.url_helpers" do
25
+ Devise.include_helpers(Devise::Controllers)
26
+ end
27
+
28
+ initializer "devise.omniauth", after: :load_config_initializers, before: :build_middleware_stack do |app|
29
+ Devise.omniauth_configs.each do |provider, config|
30
+ app.middleware.use config.strategy_class, *config.args do |strategy|
31
+ config.strategy = strategy
32
+ end
33
+ end
34
+
35
+ if Devise.omniauth_configs.any?
36
+ Devise.include_helpers(Devise::OmniAuth)
37
+ end
38
+ end
39
+
40
+ initializer "devise.secret_key" do |app|
41
+ Devise.secret_key ||= app.secret_key_base
42
+
43
+ Devise.token_generator ||=
44
+ if secret_key = Devise.secret_key
45
+ Devise::TokenGenerator.new(
46
+ ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))
47
+ )
48
+ end
49
+ end
50
+
51
+ initializer "devise.configure_zeitwerk" do
52
+ if Rails.autoloaders.zeitwerk_enabled? && !defined?(ActionMailer)
53
+ Rails.autoloaders.main.ignore("#{root}/app/mailers/devise/mailer.rb")
54
+ end
55
+ end
56
+ end
57
+ end