devise-multi_email 1.0.0 → 1.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.
- checksums.yaml +4 -4
- data/.simplecov +6 -0
- data/Gemfile +2 -0
- data/README.md +89 -11
- data/lib/devise/multi_email/models/confirmable.rb +2 -11
- data/lib/devise/multi_email/models/validatable.rb +7 -1
- data/lib/devise/multi_email/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2b9c44fd5e0d7e67068e283c110c3d5bcf2578d
|
4
|
+
data.tar.gz: 6c6101cc82b5f18131fb3a44383953424ad4c433
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77aae6065dcb2ce816df78945ea39addbb4c3550f80252ad5048ea81fbd38f7360ec92678574a554a54591c4c1fac9eee23433935145a1fe2ee2e4e37d563e08
|
7
|
+
data.tar.gz: ef10791a3e1818069f8138373eb11fb277e63f4fbdaa5c40ed451f9c9bf1a6ea4b756762a94024499aa6389f742fa54ba23084cb31256421819a4f80b463bf0d
|
data/.simplecov
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,106 @@
|
|
1
|
-
# Devise::MultiEmail [](https://travis-ci.org/allenwq/devise-multi_email)
|
1
|
+
# Devise::MultiEmail [](https://travis-ci.org/allenwq/devise-multi_email) [](https://coveralls.io/github/allenwq/devise-multi_email?branch=master)
|
2
2
|
|
3
|
-
|
3
|
+
Let [devise](https://github.com/plataformatec/devise) support multilpe emails, it allows you to:
|
4
|
+
- Login with multiple emails
|
5
|
+
- Send confirmations to multiple emails
|
6
|
+
- Recover the password with any of the emails
|
7
|
+
- Validations for multiple emails
|
4
8
|
|
5
|
-
|
9
|
+
`:multi_email_authenticatable`, `:multi_email_confirmable` and `:multi_email_validatable` are provided by devise-multi_email.
|
6
10
|
|
7
|
-
##
|
11
|
+
## Getting Started
|
8
12
|
|
9
|
-
Add this line to your application's Gemfile:
|
13
|
+
Add this line to your application's Gemfile, devise-multi_email has been tested with devise 4.0 and rails 4.2:
|
10
14
|
|
11
15
|
```ruby
|
12
16
|
gem 'devise-multi_email'
|
13
17
|
```
|
14
18
|
|
15
|
-
|
19
|
+
Suppose you have already setup devise, your `User` model might look like this:
|
16
20
|
|
17
|
-
|
21
|
+
```ruby
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
devise :database_authenticatable, :registerable
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
In order to let your `User` support multiple emails, with `devise-multi_email` what you need to do is just:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class User < ActiveRecord::Base
|
31
|
+
has_many :emails
|
32
|
+
|
33
|
+
# Replace :database_authenticatable, with :multi_email_authenticatable
|
34
|
+
devise :multi_email_authenticatable, :registerable
|
35
|
+
end
|
36
|
+
|
37
|
+
class Email < ActiveRecord::Base
|
38
|
+
belongs_to :user
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Note that `:email` column should be moved from users table to the emails table, and a new `primary` boolean column should be added to the emails table (so that all the emails will be sent to the primary email, and `user.email` will give you the primary email address). Your emails table's migration should look like:
|
43
|
+
```ruby
|
44
|
+
create_table :emails do |t|
|
45
|
+
t.integer :user_id
|
46
|
+
t.string :email
|
47
|
+
t.boolean :primary
|
48
|
+
end
|
49
|
+
```
|
18
50
|
|
19
|
-
|
51
|
+
## Confirmable with multiple emails
|
52
|
+
Sending different confirmaitons to different emails is supported. What you need to do is:
|
20
53
|
|
21
|
-
|
54
|
+
Declare `devise :multi_email_confirmable` in your `User` model:
|
55
|
+
```ruby
|
56
|
+
class User < ActiveRecord::Base
|
57
|
+
has_many :emails
|
58
|
+
|
59
|
+
# You should not declare :confiramble and :multi_email_confirmable at the same time.
|
60
|
+
devise :multi_email_authenticatable, :registerable, :multi_email_confirmable
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Add `:confirmation_token`, `:confirmed_at` and `:confirmation_sent_at` to your emails table:
|
65
|
+
```ruby
|
66
|
+
create_table :emails do |t|
|
67
|
+
t.integer :user_id
|
68
|
+
t.string :email
|
69
|
+
t.boolean :primary, default: false
|
70
|
+
|
71
|
+
## Confirmable
|
72
|
+
t.string :confirmation_token
|
73
|
+
t.datetime :confirmed_at
|
74
|
+
t.datetime :confirmation_sent_at
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Then all the methods in devise confirmable are avalible in your `Email` model. You can do `Email#send_confirmation_instructions` for each of your email. And `User#send_confirmation_instructions` will be delegated to the primary email.
|
79
|
+
|
80
|
+
## Validatable with multiple emails
|
81
|
+
Declare `devise :multi_email_validatable` in the user model, then all the user emails will be validated:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class User < ActiveRecord::Base
|
85
|
+
has_many :emails
|
86
|
+
|
87
|
+
# You should not declare :validatable and :multi_email_validatable at the same time.
|
88
|
+
devise :multi_email_authenticatable, :registerable, :multi_email_validatable
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
## What's more
|
93
|
+
|
94
|
+
The gem works with all other devise modules just as normal, you don't need to add the `multi_email` prefix.
|
95
|
+
```ruby
|
96
|
+
devise :multi_email_authenticatable, :multi_email_confirmable, :multi_email_validatable, :lockable,
|
97
|
+
:recoverable, :registerable, :rememberable, :timeoutable, :trackable
|
98
|
+
```
|
22
99
|
|
23
|
-
##
|
100
|
+
## Issues
|
101
|
+
You need to implement add/delete emails for a user as well as set/unset primary email.
|
24
102
|
|
25
|
-
|
103
|
+
You can do `email.send_confirmation_instructions` for every email, but you also need to handle this logic in some place(excpet for the primary email). e.g. After a new email was added by a user, you might want to provide some buttons to allow user to resend confirmation instrucitons for that email.
|
26
104
|
|
27
105
|
## Development
|
28
106
|
|
@@ -33,17 +33,8 @@ module Devise
|
|
33
33
|
|
34
34
|
module InstanceReplacementMethods
|
35
35
|
delegate :skip_confirmation!, :skip_confirmation_notification!, :skip_reconfirmation!, :confirmation_required?,
|
36
|
-
:confirmation_token, :confirmed_at, :confirmation_sent_at, :confirm, :confirmed?,
|
37
|
-
:reconfirmation_required?, to: :primary_email_record
|
38
|
-
|
39
|
-
def unconfirmed_email
|
40
|
-
primary_email_record.try(:unconfirmed_email)
|
41
|
-
end
|
42
|
-
|
43
|
-
def pending_reconfirmation?
|
44
|
-
primary_email = primary_email_record
|
45
|
-
primary_email && primary_email.pending_reconfirmation?
|
46
|
-
end
|
36
|
+
:confirmation_token, :confirmed_at, :confirmation_sent_at, :confirm, :confirmed?, :unconfirmed_email,
|
37
|
+
:reconfirmation_required?, :pending_reconfirmation?, to: :primary_email_record, allow_nil: true
|
47
38
|
|
48
39
|
# This need to be forwarded to the email that the user logged in with
|
49
40
|
def active_for_authentication?
|
@@ -25,6 +25,7 @@ module Devise
|
|
25
25
|
|
26
26
|
included do
|
27
27
|
devise :validatable
|
28
|
+
validates Devise::Models::MultiEmailAuthenticatable::EMAILS_ASSOCIATION, presence: true
|
28
29
|
|
29
30
|
after_validation :propagate_email_errors
|
30
31
|
email_class.send :include, EmailValidatable
|
@@ -41,7 +42,12 @@ module Devise
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def propagate_email_errors
|
44
|
-
|
45
|
+
email_error_key = self.class::EMAILS_ASSOCIATION
|
46
|
+
if respond_to?("#{self.class::EMAILS_ASSOCIATION}_attributes=")
|
47
|
+
email_error_key = "#{email_error_key}.email".to_sym
|
48
|
+
end
|
49
|
+
|
50
|
+
return if (email_errors = errors.delete(email_error_key)).nil?
|
45
51
|
|
46
52
|
email_errors.each do |error|
|
47
53
|
errors.add(:email, error)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-multi_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ALLEN WANG QIANG
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".simplecov"
|
64
65
|
- ".travis.yml"
|
65
66
|
- CODE_OF_CONDUCT.md
|
66
67
|
- Gemfile
|