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,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ # Responsible for handling devise mappings and routes configuration. Each
5
+ # resource configured by devise_for in routes is actually creating a mapping
6
+ # object. You can refer to devise_for in routes for usage options.
7
+ #
8
+ # The required value in devise_for is actually not used internally, but it's
9
+ # inflected to find all other values.
10
+ #
11
+ # map.devise_for :users
12
+ # mapping = Devise.mappings[:user]
13
+ #
14
+ # mapping.name #=> :user
15
+ # # is the scope used in controllers and warden, given in the route as :singular.
16
+ #
17
+ # mapping.as #=> "users"
18
+ # # how the mapping should be search in the path, given in the route as :as.
19
+ #
20
+ # mapping.to #=> User
21
+ # # is the class to be loaded from routes, given in the route as :class_name.
22
+ #
23
+ # mapping.modules #=> [:authenticatable]
24
+ # # is the modules included in the class
25
+ #
26
+ class Mapping #:nodoc:
27
+ attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
28
+ :class_name, :sign_out_via, :format, :used_routes, :used_helpers,
29
+ :failure_app, :router_name
30
+
31
+ alias :name :singular
32
+
33
+ # Receives an object and finds a scope for it. If a scope cannot be found,
34
+ # raises an error. If a symbol is given, it's considered to be the scope.
35
+ def self.find_scope!(obj)
36
+ obj = obj.devise_scope if obj.respond_to?(:devise_scope)
37
+ case obj
38
+ when String, Symbol
39
+ return obj.to_sym
40
+ when Class
41
+ Devise.mappings.each_value { |m| return m.name if obj <= m.to }
42
+ else
43
+ Devise.mappings.each_value { |m| return m.name if obj.is_a?(m.to) }
44
+ end
45
+
46
+ raise "Could not find a valid mapping for #{obj.inspect}"
47
+ end
48
+
49
+ def self.find_by_path!(path, path_type = :fullpath)
50
+ Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) }
51
+ raise "Could not find a valid mapping for path #{path.inspect}"
52
+ end
53
+
54
+ def initialize(name, options) #:nodoc:
55
+ @scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s
56
+ @singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
57
+
58
+ @class_name = (options[:class_name] || name.to_s.classify).to_s
59
+ @klass = Devise.ref(@class_name)
60
+
61
+ @path = (options[:path] || name).to_s
62
+ @path_prefix = options[:path_prefix]
63
+
64
+ @sign_out_via = options[:sign_out_via] || Devise.sign_out_via
65
+ @format = options[:format]
66
+
67
+ @router_name = options[:router_name]
68
+
69
+ default_failure_app(options)
70
+ default_controllers(options)
71
+ default_path_names(options)
72
+ default_used_route(options)
73
+ default_used_helpers(options)
74
+ end
75
+
76
+ # Return modules for the mapping.
77
+ def modules
78
+ @modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []
79
+ end
80
+
81
+ # Gives the class the mapping points to.
82
+ def to
83
+ @klass.get
84
+ end
85
+
86
+ def strategies
87
+ @strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse
88
+ end
89
+
90
+ def no_input_strategies
91
+ self.strategies & Devise::NO_INPUT
92
+ end
93
+
94
+ def routes
95
+ @routes ||= ROUTES.values_at(*self.modules).compact.uniq
96
+ end
97
+
98
+ def authenticatable?
99
+ @authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ }
100
+ end
101
+
102
+ def fullpath
103
+ "/#{@path_prefix}/#{@path}".squeeze("/")
104
+ end
105
+
106
+ # Create magic predicates for verifying what module is activated by this map.
107
+ # Example:
108
+ #
109
+ # def confirmable?
110
+ # self.modules.include?(:confirmable)
111
+ # end
112
+ #
113
+ def self.add_module(m)
114
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
115
+ def #{m}?
116
+ self.modules.include?(:#{m})
117
+ end
118
+ METHOD
119
+ end
120
+
121
+ private
122
+
123
+ def default_failure_app(options)
124
+ @failure_app = options[:failure_app] || Devise::FailureApp
125
+ if @failure_app.is_a?(String)
126
+ ref = Devise.ref(@failure_app)
127
+ @failure_app = lambda { |env| ref.get.call(env) }
128
+ end
129
+ end
130
+
131
+ def default_controllers(options)
132
+ mod = options[:module] || "devise"
133
+ @controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
134
+ @controllers.merge!(options[:controllers]) if options[:controllers]
135
+ @controllers.each { |k,v| @controllers[k] = v.to_s }
136
+ end
137
+
138
+ def default_path_names(options)
139
+ @path_names = Hash.new { |h,k| h[k] = k.to_s }
140
+ @path_names[:registration] = ""
141
+ @path_names.merge!(options[:path_names]) if options[:path_names]
142
+ end
143
+
144
+ def default_constraints(options)
145
+ @constraints = Hash.new
146
+ @constraints.merge!(options[:constraints]) if options[:constraints]
147
+ end
148
+
149
+ def default_defaults(options)
150
+ @defaults = Hash.new
151
+ @defaults.merge!(options[:defaults]) if options[:defaults]
152
+ end
153
+
154
+ def default_used_route(options)
155
+ singularizer = lambda { |s| s.to_s.singularize.to_sym }
156
+
157
+ if options.has_key?(:only)
158
+ @used_routes = self.routes & Array(options[:only]).map(&singularizer)
159
+ elsif options[:skip] == :all
160
+ @used_routes = []
161
+ else
162
+ @used_routes = self.routes - Array(options[:skip]).map(&singularizer)
163
+ end
164
+ end
165
+
166
+ def default_used_helpers(options)
167
+ singularizer = lambda { |s| s.to_s.singularize.to_sym }
168
+
169
+ if options[:skip_helpers] == true
170
+ @used_helpers = @used_routes
171
+ elsif skip = options[:skip_helpers]
172
+ @used_helpers = self.routes - Array(skip).map(&singularizer)
173
+ else
174
+ @used_helpers = self.routes
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,302 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'devise/hooks/activatable'
4
+ require 'devise/hooks/csrf_cleaner'
5
+
6
+ module Devise
7
+ module Models
8
+ # Authenticatable module. Holds common settings for authentication.
9
+ #
10
+ # == Options
11
+ #
12
+ # Authenticatable adds the following options to +devise+:
13
+ #
14
+ # * +authentication_keys+: parameters used for authentication. By default [:email].
15
+ #
16
+ # * +http_authentication_key+: map the username passed via HTTP Auth to this parameter. Defaults to
17
+ # the first element in +authentication_keys+.
18
+ #
19
+ # * +request_keys+: parameters from the request object used for authentication.
20
+ # By specifying a symbol (which should be a request method), it will automatically be
21
+ # passed to find_for_authentication method and considered in your model lookup.
22
+ #
23
+ # For instance, if you set :request_keys to [:subdomain], :subdomain will be considered
24
+ # as key on authentication. This can also be a hash where the value is a boolean specifying
25
+ # if the value is required or not.
26
+ #
27
+ # * +http_authenticatable+: if this model allows http authentication. By default false.
28
+ # It also accepts an array specifying the strategies that should allow http.
29
+ #
30
+ # * +params_authenticatable+: if this model allows authentication through request params. By default true.
31
+ # It also accepts an array specifying the strategies that should allow params authentication.
32
+ #
33
+ # * +skip_session_storage+: By default Devise will store the user in session.
34
+ # By default is set to skip_session_storage: [:http_auth].
35
+ #
36
+ # == active_for_authentication?
37
+ #
38
+ # After authenticating a user and in each request, Devise checks if your model is active by
39
+ # calling model.active_for_authentication?. This method is overwritten by other devise modules. For instance,
40
+ # :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
41
+ #
42
+ # You can overwrite this method yourself, but if you do, don't forget to call super:
43
+ #
44
+ # def active_for_authentication?
45
+ # super && special_condition_is_valid?
46
+ # end
47
+ #
48
+ # Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using
49
+ # the inactive_message method. You can overwrite it as well:
50
+ #
51
+ # def inactive_message
52
+ # special_condition_is_valid? ? super : :special_condition_is_not_valid
53
+ # end
54
+ #
55
+ module Authenticatable
56
+ extend ActiveSupport::Concern
57
+
58
+ UNSAFE_ATTRIBUTES_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
59
+ :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
60
+ :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
61
+ :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
62
+
63
+ included do
64
+ class_attribute :devise_modules, instance_writer: false
65
+ self.devise_modules ||= []
66
+
67
+ before_validation :downcase_keys
68
+ before_validation :strip_whitespace
69
+ end
70
+
71
+ def self.required_fields(klass)
72
+ []
73
+ end
74
+
75
+ # Check if the current object is valid for authentication. This method and
76
+ # find_for_authentication are the methods used in a Warden::Strategy to check
77
+ # if a model should be signed in or not.
78
+ #
79
+ # However, you should not overwrite this method, you should overwrite active_for_authentication?
80
+ # and inactive_message instead.
81
+ def valid_for_authentication?
82
+ block_given? ? yield : true
83
+ end
84
+
85
+ def unauthenticated_message
86
+ :invalid
87
+ end
88
+
89
+ def active_for_authentication?
90
+ true
91
+ end
92
+
93
+ def inactive_message
94
+ :inactive
95
+ end
96
+
97
+ def authenticatable_salt
98
+ end
99
+
100
+ # Redefine serializable_hash in models for more secure defaults.
101
+ # By default, it removes from the serializable model all attributes that
102
+ # are *not* accessible. You can remove this default by using :force_except
103
+ # and passing a new list of attributes you want to exempt. All attributes
104
+ # given to :except will simply add names to exempt to Devise internal list.
105
+ def serializable_hash(options = nil)
106
+ options = options.try(:dup) || {}
107
+ options[:except] = Array(options[:except]).dup
108
+
109
+ if options[:force_except]
110
+ options[:except].concat Array(options[:force_except])
111
+ else
112
+ options[:except].concat UNSAFE_ATTRIBUTES_FOR_SERIALIZATION
113
+ end
114
+
115
+ super(options)
116
+ end
117
+
118
+ # Redefine inspect using serializable_hash, to ensure we don't accidentally
119
+ # leak passwords into exceptions.
120
+ def inspect
121
+ inspection = serializable_hash.collect do |k,v|
122
+ "#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
123
+ end
124
+ "#<#{self.class} #{inspection.join(", ")}>"
125
+ end
126
+
127
+ protected
128
+
129
+ def devise_mailer
130
+ Devise.mailer
131
+ end
132
+
133
+ # This is an internal method called every time Devise needs
134
+ # to send a notification/mail. This can be overridden if you
135
+ # need to customize the e-mail delivery logic. For instance,
136
+ # if you are using a queue to deliver e-mails (active job, delayed
137
+ # job, sidekiq, resque, etc), you must add the delivery to the queue
138
+ # just after the transaction was committed. To achieve this,
139
+ # you can override send_devise_notification to store the
140
+ # deliveries until the after_commit callback is triggered.
141
+ #
142
+ # The following example uses Active Job's `deliver_later` :
143
+ #
144
+ # class User
145
+ # devise :database_authenticatable, :confirmable
146
+ #
147
+ # after_commit :send_pending_devise_notifications
148
+ #
149
+ # protected
150
+ #
151
+ # def send_devise_notification(notification, *args)
152
+ # # If the record is new or changed then delay the
153
+ # # delivery until the after_commit callback otherwise
154
+ # # send now because after_commit will not be called.
155
+ # # For Rails < 6 use `changed?` instead of `saved_changes?`.
156
+ # if new_record? || saved_changes?
157
+ # pending_devise_notifications << [notification, args]
158
+ # else
159
+ # render_and_send_devise_message(notification, *args)
160
+ # end
161
+ # end
162
+ #
163
+ # private
164
+ #
165
+ # def send_pending_devise_notifications
166
+ # pending_devise_notifications.each do |notification, args|
167
+ # render_and_send_devise_message(notification, *args)
168
+ # end
169
+ #
170
+ # # Empty the pending notifications array because the
171
+ # # after_commit hook can be called multiple times which
172
+ # # could cause multiple emails to be sent.
173
+ # pending_devise_notifications.clear
174
+ # end
175
+ #
176
+ # def pending_devise_notifications
177
+ # @pending_devise_notifications ||= []
178
+ # end
179
+ #
180
+ # def render_and_send_devise_message(notification, *args)
181
+ # message = devise_mailer.send(notification, self, *args)
182
+ #
183
+ # # Deliver later with Active Job's `deliver_later`
184
+ # if message.respond_to?(:deliver_later)
185
+ # message.deliver_later
186
+ # else
187
+ # message.deliver_now
188
+ # end
189
+ # end
190
+ #
191
+ # end
192
+ #
193
+ def send_devise_notification(notification, *args)
194
+ message = devise_mailer.send(notification, self, *args)
195
+ message.deliver_now
196
+ end
197
+
198
+ def downcase_keys
199
+ self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase) }
200
+ end
201
+
202
+ def strip_whitespace
203
+ self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip) }
204
+ end
205
+
206
+ def apply_to_attribute_or_variable(attr, method)
207
+ if self[attr]
208
+ self[attr] = self[attr].try(method)
209
+
210
+ # Use respond_to? here to avoid a regression where globally
211
+ # configured strip_whitespace_keys or case_insensitive_keys were
212
+ # attempting to strip or downcase when a model didn't have the
213
+ # globally configured key.
214
+ elsif respond_to?(attr) && respond_to?("#{attr}=")
215
+ new_value = send(attr).try(method)
216
+ send("#{attr}=", new_value)
217
+ end
218
+ end
219
+
220
+ module ClassMethods
221
+ Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
222
+ :case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage,
223
+ :http_authentication_key)
224
+
225
+ def serialize_into_session(record)
226
+ [record.to_key, record.authenticatable_salt]
227
+ end
228
+
229
+ def serialize_from_session(key, salt)
230
+ record = to_adapter.get(key)
231
+ record if record && record.authenticatable_salt == salt
232
+ end
233
+
234
+ def params_authenticatable?(strategy)
235
+ params_authenticatable.is_a?(Array) ?
236
+ params_authenticatable.include?(strategy) : params_authenticatable
237
+ end
238
+
239
+ def http_authenticatable?(strategy)
240
+ http_authenticatable.is_a?(Array) ?
241
+ http_authenticatable.include?(strategy) : http_authenticatable
242
+ end
243
+
244
+ # Find first record based on conditions given (ie by the sign in form).
245
+ # This method is always called during an authentication process but
246
+ # it may be wrapped as well. For instance, database authenticatable
247
+ # provides a `find_for_database_authentication` that wraps a call to
248
+ # this method. This allows you to customize both database authenticatable
249
+ # or the whole authenticate stack by customize `find_for_authentication.`
250
+ #
251
+ # Overwrite to add customized conditions, create a join, or maybe use a
252
+ # namedscope to filter records while authenticating.
253
+ # Example:
254
+ #
255
+ # def self.find_for_authentication(tainted_conditions)
256
+ # find_first_by_auth_conditions(tainted_conditions, active: true)
257
+ # end
258
+ #
259
+ # Finally, notice that Devise also queries for users in other scenarios
260
+ # besides authentication, for example when retrieving a user to send
261
+ # an e-mail for password reset. In such cases, find_for_authentication
262
+ # is not called.
263
+ def find_for_authentication(tainted_conditions)
264
+ find_first_by_auth_conditions(tainted_conditions)
265
+ end
266
+
267
+ def find_first_by_auth_conditions(tainted_conditions, opts = {})
268
+ to_adapter.find_first(devise_parameter_filter.filter(tainted_conditions).merge(opts))
269
+ end
270
+
271
+ # Find or initialize a record setting an error if it can't be found.
272
+ def find_or_initialize_with_error_by(attribute, value, error = :invalid) #:nodoc:
273
+ find_or_initialize_with_errors([attribute], { attribute => value }, error)
274
+ end
275
+
276
+ # Find or initialize a record with group of attributes based on a list of required attributes.
277
+ def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc:
278
+ attributes.try(:permit!)
279
+ attributes = attributes.to_h.with_indifferent_access
280
+ .slice(*required_attributes)
281
+ .delete_if { |key, value| value.blank? }
282
+
283
+ if attributes.size == required_attributes.size
284
+ record = find_first_by_auth_conditions(attributes) and return record
285
+ end
286
+
287
+ new(devise_parameter_filter.filter(attributes)).tap do |record|
288
+ required_attributes.each do |key|
289
+ record.errors.add(key, attributes[key].blank? ? :blank : error)
290
+ end
291
+ end
292
+ end
293
+
294
+ protected
295
+
296
+ def devise_parameter_filter
297
+ @devise_parameter_filter ||= Devise::ParameterFilter.new(case_insensitive_keys, strip_whitespace_keys)
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end