effective_resources 2.11.0 → 2.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8000b25d219e4ce996d1c768682448fc912180f9d0b4808584182e94698255be
4
- data.tar.gz: d1f99291b1a0072284c0432335541987b6e670b7e491d0e405befbcd42000282
3
+ metadata.gz: 70b3835f1e45128ade83d38d69adbcd8096fd5aecce4882028d0512dab970dae
4
+ data.tar.gz: 7c38e5cb62a55b4fa4924970aad1b0f45cf06b0dccedb41770f8df394e98a9c0
5
5
  SHA512:
6
- metadata.gz: 2e36bf1f67caf8510e570573621320ba328a311eebc60b8f764a0f811b5b49aedc713f615cb25ef5510786563e9b849a15efd1f4eef6dc86872bc4c26908af85
7
- data.tar.gz: b6c593560fb53b762eee968c3d53dda47a208493155ef781089cddecc25771dbd18e748ca3336afdf29f187b2801c00ac07a2452457512c4c5788cba7777fb12
6
+ metadata.gz: 50be7d9a989a25f8aa6777e85603c18b8ccc3be72e78aa35e4aa83814ca0fa74371de434c1138dc9a2331b57d79c1e032dbf987628c2b3b800b8b3819b26eb3d
7
+ data.tar.gz: 46e3229e7ecc0a7e989ac022afed029183b96e9a225f7a3d93edc3d9ff0a14a37682bf4d1685e1c3ebf3f8c8a5760e0cd09eafc7346eb940bf13d5aecd1752ad
data/README.md CHANGED
@@ -392,6 +392,43 @@ def to_select2
392
392
  end
393
393
  ```
394
394
 
395
+ ## Authentication
396
+ Effective Resources is designed to work with Devise. It also adds support for an `alternate email`
397
+ for authentication. You just need to add an `alternate_email` column to your `User` model table.
398
+
399
+ After that column is added, any user would be able to log in with either their `email` or their
400
+ `alternate_email`.
401
+
402
+ You can also create another mailer for `devise` in order to send password reset emails to the both
403
+ the primary `email` and also the `alternate_email`, like this:
404
+
405
+ ```ruby
406
+ class DeviseMailer < Devise::Mailer
407
+ # Overriding Devise's #headers_for to support alternate_email when present
408
+ def headers_for(action, opts)
409
+ headers = super(action, opts)
410
+
411
+ if [:reset_password_instructions].include?(action)
412
+ headers.merge!(
413
+ to: [resource.email, resource.try(:alternate_email)].compact.uniq
414
+ )
415
+ end
416
+
417
+ headers
418
+ end
419
+ end
420
+ ```
421
+
422
+ and set this new mailer to be used by `devise` in `config/initializers/devise.rb`:
423
+
424
+ ```ruby
425
+ Devise.setup do |config|
426
+ # ...
427
+ config.mailer = 'DeviseMailer'
428
+ # ...
429
+ end
430
+ ```
431
+
395
432
  ## Testing
396
433
 
397
434
  Run tests by:
@@ -187,13 +187,11 @@ module EffectiveDeviseUser
187
187
  # https://github.com/heartcombo/devise/blob/f6e73e5b5c8f519f4be29ac9069c6ed8a2343ce4/lib/devise/models/authenticatable.rb#L276
188
188
  def find_first_by_auth_conditions(tainted_conditions, opts = {})
189
189
  conditions = devise_parameter_filter.filter(tainted_conditions).merge(opts)
190
- email = conditions[:email]
191
- conditions.delete(:email)
192
190
 
193
- user = to_adapter.find_first(conditions.merge(email: email))
191
+ user = to_adapter.find_first(conditions)
194
192
  return user if user.present? && user.persisted?
195
193
 
196
- to_adapter.find_first(conditions.merge(alternate_email: email)) if respond_to?(:alternate_email)
194
+ to_adapter.find_first(alternate_email: conditions[:email]) if has_alternate_email?
197
195
  end
198
196
 
199
197
  # https://github.com/heartcombo/devise/blob/f6e73e5b5c8f519f4be29ac9069c6ed8a2343ce4/lib/devise/models/database_authenticatable.rb#L216
@@ -202,11 +200,9 @@ module EffectiveDeviseUser
202
200
  primary_or_alternate_email = conditions[:email]
203
201
  conditions.delete(:email)
204
202
 
205
- has_alternate_email = 'alternate_email'.in? column_names
206
-
207
- raise "Expected an email #{has_alternate_email ? 'or alternate email' : ''} but got [#{primary_or_alternate_email}] instead" if primary_or_alternate_email.blank?
203
+ raise "Expected an email #{has_alternate_email? ? 'or alternate email' : ''} but got [#{primary_or_alternate_email}] instead" if primary_or_alternate_email.blank?
208
204
 
209
- query = if has_alternate_email
205
+ query = if has_alternate_email?
210
206
  "lower(email) = :value OR lower(alternate_email) = :value"
211
207
  else
212
208
  "lower(email) = :value"
@@ -218,6 +214,10 @@ module EffectiveDeviseUser
218
214
  .first
219
215
  end
220
216
 
217
+ def has_alternate_email?
218
+ 'alternate_email'.in? column_names
219
+ end
220
+
221
221
  end
222
222
 
223
223
  # EffectiveDeviseUser Instance Methods
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.11.0'.freeze
2
+ VERSION = '2.11.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails