effective_resources 2.11.0 → 2.11.2
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 +4 -4
- data/README.md +37 -0
- data/app/models/concerns/effective_devise_user.rb +21 -19
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7420e7773e862ace77933d82892a2536a3502a8e9780670e7951368a043b63e
|
4
|
+
data.tar.gz: f27995719216c1a0d9eeb4d0cacdf5591726322301a87b3f19ee8f8d0e9df450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae042cbd0de9cacc8cac925db8339254ab7cd144076acac9f3464b2fe09e5572c8c0cd691766810a013ba92834ceda19522f70fcf6928065c7f268943e0b592
|
7
|
+
data.tar.gz: 5d50084e5ecf6c49c6861027e0240f8be521c43ea16327cd5e69f8fa22f46326b5c0b1af7e30fb4c5bba30c011053bf89cd2b2104348ec682921f988b13513f8
|
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,41 +187,43 @@ 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
|
191
|
+
user = to_adapter.find_first(conditions)
|
194
192
|
return user if user.present? && user.persisted?
|
195
193
|
|
196
|
-
to_adapter.find_first(
|
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
|
200
198
|
def find_for_database_authentication(warden_conditions)
|
201
199
|
conditions = warden_conditions.dup.presence || {}
|
202
|
-
primary_or_alternate_email = conditions[:email]
|
203
|
-
conditions.delete(:email)
|
204
200
|
|
205
|
-
|
201
|
+
email = conditions.delete(:email).to_s.strip.downcase
|
202
|
+
raise "Expected an email condition but got #{conditions} instead" unless email.present?
|
206
203
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
end
|
204
|
+
if has_alternate_email?
|
205
|
+
where(conditions).where('email = :email OR alternate_email = :email', email: email).first
|
206
|
+
else
|
207
|
+
where(conditions).where(email: email).first
|
208
|
+
end
|
209
|
+
end
|
214
210
|
|
215
|
-
|
216
|
-
|
217
|
-
.where(query, value: primary_or_alternate_email.strip.downcase)
|
218
|
-
.first
|
211
|
+
def has_alternate_email?
|
212
|
+
column_names.include?('alternate_email')
|
219
213
|
end
|
220
214
|
|
215
|
+
def find_by_any_email(value)
|
216
|
+
email = value.to_s.strip.downcase
|
217
|
+
|
218
|
+
if has_alternate_email?
|
219
|
+
where(email: email).or(where(alternate_email: email)).first
|
220
|
+
else
|
221
|
+
where(email: email).first
|
222
|
+
end
|
223
|
+
end
|
221
224
|
end
|
222
225
|
|
223
226
|
# EffectiveDeviseUser Instance Methods
|
224
|
-
|
225
227
|
def alternate_email=(value)
|
226
228
|
super(value.to_s.strip.downcase.presence)
|
227
229
|
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.
|
4
|
+
version: 2.11.2
|
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-
|
11
|
+
date: 2023-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|