devise-multi_email 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/CHANGELOG.md +15 -2
- data/Gemfile +2 -9
- data/README.md +69 -18
- data/devise-multi_email.gemspec +4 -0
- data/examples/rails5_app/.gitignore +21 -0
- data/examples/rails5_app/Gemfile +55 -0
- data/examples/rails5_app/Gemfile.lock +185 -0
- data/examples/rails5_app/README.md +24 -0
- data/examples/rails5_app/Rakefile +6 -0
- data/examples/rails5_app/app/assets/config/manifest.js +3 -0
- data/examples/rails5_app/app/assets/images/.keep +0 -0
- data/examples/rails5_app/app/assets/javascripts/application.js +16 -0
- data/examples/rails5_app/app/assets/javascripts/cable.js +13 -0
- data/examples/rails5_app/app/assets/javascripts/channels/.keep +0 -0
- data/examples/rails5_app/app/assets/stylesheets/application.css +15 -0
- data/examples/rails5_app/app/channels/application_cable/channel.rb +4 -0
- data/examples/rails5_app/app/channels/application_cable/connection.rb +4 -0
- data/examples/rails5_app/app/controllers/application_controller.rb +3 -0
- data/examples/rails5_app/app/controllers/concerns/.keep +0 -0
- data/examples/rails5_app/app/helpers/application_helper.rb +2 -0
- data/examples/rails5_app/app/jobs/application_job.rb +2 -0
- data/examples/rails5_app/app/mailers/application_mailer.rb +4 -0
- data/examples/rails5_app/app/models/application_record.rb +3 -0
- data/examples/rails5_app/app/models/concerns/.keep +0 -0
- data/examples/rails5_app/app/models/email.rb +3 -0
- data/examples/rails5_app/app/models/user.rb +9 -0
- data/examples/rails5_app/app/views/layouts/application.html.erb +14 -0
- data/examples/rails5_app/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails5_app/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails5_app/bin/bundle +3 -0
- data/examples/rails5_app/bin/rails +4 -0
- data/examples/rails5_app/bin/rake +4 -0
- data/examples/rails5_app/bin/setup +34 -0
- data/examples/rails5_app/bin/update +29 -0
- data/examples/rails5_app/config/application.rb +15 -0
- data/examples/rails5_app/config/boot.rb +3 -0
- data/examples/rails5_app/config/cable.yml +9 -0
- data/examples/rails5_app/config/database.yml +25 -0
- data/examples/rails5_app/config/environment.rb +5 -0
- data/examples/rails5_app/config/environments/development.rb +56 -0
- data/examples/rails5_app/config/environments/production.rb +86 -0
- data/examples/rails5_app/config/environments/test.rb +42 -0
- data/examples/rails5_app/config/initializers/application_controller_renderer.rb +6 -0
- data/examples/rails5_app/config/initializers/assets.rb +11 -0
- data/examples/rails5_app/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails5_app/config/initializers/cookies_serializer.rb +5 -0
- data/examples/rails5_app/config/initializers/devise.rb +274 -0
- data/examples/rails5_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/rails5_app/config/initializers/inflections.rb +16 -0
- data/examples/rails5_app/config/initializers/mime_types.rb +4 -0
- data/examples/rails5_app/config/initializers/new_framework_defaults.rb +24 -0
- data/examples/rails5_app/config/initializers/session_store.rb +3 -0
- data/examples/rails5_app/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails5_app/config/locales/devise.en.yml +62 -0
- data/examples/rails5_app/config/locales/en.yml +23 -0
- data/examples/rails5_app/config/puma.rb +47 -0
- data/examples/rails5_app/config/routes.rb +4 -0
- data/examples/rails5_app/config/secrets.yml +22 -0
- data/examples/rails5_app/config/spring.rb +6 -0
- data/examples/rails5_app/config.ru +5 -0
- data/examples/rails5_app/db/migrate/20170307140813_devise_create_users.rb +49 -0
- data/examples/rails5_app/db/migrate/20170307145547_add_password_salt_to_users.rb +5 -0
- data/examples/rails5_app/db/schema.rb +44 -0
- data/examples/rails5_app/db/seeds.rb +7 -0
- data/examples/rails5_app/lib/assets/.keep +0 -0
- data/examples/rails5_app/lib/tasks/.keep +0 -0
- data/examples/rails5_app/log/.keep +0 -0
- data/examples/rails5_app/public/404.html +67 -0
- data/examples/rails5_app/public/422.html +67 -0
- data/examples/rails5_app/public/500.html +66 -0
- data/examples/rails5_app/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/rails5_app/public/apple-touch-icon.png +0 -0
- data/examples/rails5_app/public/favicon.ico +0 -0
- data/examples/rails5_app/public/robots.txt +5 -0
- data/examples/rails5_app/test/controllers/.keep +0 -0
- data/examples/rails5_app/test/fixtures/.keep +0 -0
- data/examples/rails5_app/test/fixtures/files/.keep +0 -0
- data/examples/rails5_app/test/helpers/.keep +0 -0
- data/examples/rails5_app/test/integration/.keep +0 -0
- data/examples/rails5_app/test/mailers/.keep +0 -0
- data/examples/rails5_app/test/models/.keep +0 -0
- data/examples/rails5_app/test/test_helper.rb +10 -0
- data/examples/rails5_app/tmp/.keep +0 -0
- data/examples/rails5_app/vendor/assets/javascripts/.keep +0 -0
- data/examples/rails5_app/vendor/assets/stylesheets/.keep +0 -0
- data/gemfiles/rails_4_2.gemfile +5 -0
- data/gemfiles/rails_5_0.gemfile +5 -0
- data/gemfiles/rails_5_1.gemfile +5 -0
- data/lib/devise/multi_email/association_manager.rb +30 -0
- data/lib/devise/multi_email/email_model_extensions.rb +20 -0
- data/lib/devise/multi_email/email_model_manager.rb +18 -0
- data/lib/devise/multi_email/models/authenticatable.rb +23 -44
- data/lib/devise/multi_email/models/confirmable.rb +20 -21
- data/lib/devise/multi_email/models/validatable.rb +42 -38
- data/lib/devise/multi_email/parent_model_extensions.rb +27 -0
- data/lib/devise/multi_email/parent_model_manager.rb +55 -0
- data/lib/devise/multi_email/version.rb +1 -1
- data/lib/devise/multi_email.rb +32 -0
- metadata +147 -2
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'devise/multi_email/email_model_extensions'
|
2
|
+
require 'devise/multi_email/association_manager'
|
3
|
+
require 'devise/multi_email/parent_model_manager'
|
4
|
+
|
5
|
+
module Devise
|
6
|
+
module MultiEmail
|
7
|
+
module ParentModelExtensions
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
multi_email_association.include_module(EmailModelExtensions)
|
12
|
+
end
|
13
|
+
|
14
|
+
delegate Devise::MultiEmail.primary_email_method_name, to: :multi_email, allow_nil: false
|
15
|
+
|
16
|
+
def multi_email
|
17
|
+
@multi_email ||= ParentModelManager.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def multi_email_association
|
22
|
+
@multi_email ||= AssociationManager.new(self, Devise::MultiEmail.emails_association_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'devise/multi_email/email_model_extensions'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module MultiEmail
|
5
|
+
class ParentModelManager
|
6
|
+
|
7
|
+
attr_reader :record
|
8
|
+
|
9
|
+
def initialize(record)
|
10
|
+
@record = record
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets the email records that have not been deleted
|
14
|
+
def filtered_emails
|
15
|
+
emails.reject(&:destroyed?).reject(&:marked_for_destruction?)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Gets the primary email record.
|
19
|
+
def primary_email
|
20
|
+
filtered_emails.find(&:primary?)
|
21
|
+
end
|
22
|
+
alias_method Devise::MultiEmail.primary_email_method_name, :primary_email
|
23
|
+
|
24
|
+
def change_primary_email_to(new_email)
|
25
|
+
# Use Devise formatting settings for emails
|
26
|
+
formatted_email = record.class.send(:devise_parameter_filter).filter(email: new_email)[:email]
|
27
|
+
|
28
|
+
valid_emails = filtered_emails
|
29
|
+
|
30
|
+
# mark none as primary when set to nil
|
31
|
+
if new_email.nil?
|
32
|
+
valid_emails.each{ |record| record.primary = false }
|
33
|
+
|
34
|
+
# select or build an email record
|
35
|
+
else
|
36
|
+
record = valid_emails.find{ |record| record.email == formatted_email }
|
37
|
+
|
38
|
+
unless record
|
39
|
+
record = emails.build(email: formatted_email)
|
40
|
+
valid_emails << record
|
41
|
+
end
|
42
|
+
|
43
|
+
# toggle the selected record as primary and others as not
|
44
|
+
valid_emails.each{ |other| other.primary = (other == record) }
|
45
|
+
end
|
46
|
+
|
47
|
+
record
|
48
|
+
end
|
49
|
+
|
50
|
+
def emails
|
51
|
+
record.__send__(record.class.multi_email_association.name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/devise/multi_email.rb
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
require 'devise/multi_email/version'
|
2
2
|
require 'devise'
|
3
3
|
|
4
|
+
module Devise
|
5
|
+
module MultiEmail
|
6
|
+
def self.configure(&block)
|
7
|
+
yield self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parent_association_name
|
11
|
+
@parent_association_name ||= :user
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parent_association_name=(name)
|
15
|
+
@parent_association_name = name.try(:to_sym)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.emails_association_name
|
19
|
+
@emails_association_name ||= :emails
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.emails_association_name=(name)
|
23
|
+
@emails_association_name = name.try(:to_sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.primary_email_method_name
|
27
|
+
@primary_email_method_name ||= :primary_email
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.primary_email_method_name=(name)
|
31
|
+
@primary_email_method_name = name.try(:to_sym)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
4
36
|
Devise.add_module :multi_email_authenticatable, model: 'devise/multi_email/models/authenticatable'
|
5
37
|
Devise.add_module :multi_email_confirmable, model: 'devise/multi_email/models/confirmable'
|
6
38
|
Devise.add_module :multi_email_validatable, model: 'devise/multi_email/models/validatable'
|
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:
|
4
|
+
version: 2.0.0
|
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:
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -52,6 +52,62 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: capybara
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
description: Devise authenticatable, confirmable and validatable with multiple emails.
|
56
112
|
email:
|
57
113
|
- rovingbreeze@gmail.com
|
@@ -72,10 +128,99 @@ files:
|
|
72
128
|
- bin/console
|
73
129
|
- bin/setup
|
74
130
|
- devise-multi_email.gemspec
|
131
|
+
- examples/rails5_app/.gitignore
|
132
|
+
- examples/rails5_app/Gemfile
|
133
|
+
- examples/rails5_app/Gemfile.lock
|
134
|
+
- examples/rails5_app/README.md
|
135
|
+
- examples/rails5_app/Rakefile
|
136
|
+
- examples/rails5_app/app/assets/config/manifest.js
|
137
|
+
- examples/rails5_app/app/assets/images/.keep
|
138
|
+
- examples/rails5_app/app/assets/javascripts/application.js
|
139
|
+
- examples/rails5_app/app/assets/javascripts/cable.js
|
140
|
+
- examples/rails5_app/app/assets/javascripts/channels/.keep
|
141
|
+
- examples/rails5_app/app/assets/stylesheets/application.css
|
142
|
+
- examples/rails5_app/app/channels/application_cable/channel.rb
|
143
|
+
- examples/rails5_app/app/channels/application_cable/connection.rb
|
144
|
+
- examples/rails5_app/app/controllers/application_controller.rb
|
145
|
+
- examples/rails5_app/app/controllers/concerns/.keep
|
146
|
+
- examples/rails5_app/app/helpers/application_helper.rb
|
147
|
+
- examples/rails5_app/app/jobs/application_job.rb
|
148
|
+
- examples/rails5_app/app/mailers/application_mailer.rb
|
149
|
+
- examples/rails5_app/app/models/application_record.rb
|
150
|
+
- examples/rails5_app/app/models/concerns/.keep
|
151
|
+
- examples/rails5_app/app/models/email.rb
|
152
|
+
- examples/rails5_app/app/models/user.rb
|
153
|
+
- examples/rails5_app/app/views/layouts/application.html.erb
|
154
|
+
- examples/rails5_app/app/views/layouts/mailer.html.erb
|
155
|
+
- examples/rails5_app/app/views/layouts/mailer.text.erb
|
156
|
+
- examples/rails5_app/bin/bundle
|
157
|
+
- examples/rails5_app/bin/rails
|
158
|
+
- examples/rails5_app/bin/rake
|
159
|
+
- examples/rails5_app/bin/setup
|
160
|
+
- examples/rails5_app/bin/update
|
161
|
+
- examples/rails5_app/config.ru
|
162
|
+
- examples/rails5_app/config/application.rb
|
163
|
+
- examples/rails5_app/config/boot.rb
|
164
|
+
- examples/rails5_app/config/cable.yml
|
165
|
+
- examples/rails5_app/config/database.yml
|
166
|
+
- examples/rails5_app/config/environment.rb
|
167
|
+
- examples/rails5_app/config/environments/development.rb
|
168
|
+
- examples/rails5_app/config/environments/production.rb
|
169
|
+
- examples/rails5_app/config/environments/test.rb
|
170
|
+
- examples/rails5_app/config/initializers/application_controller_renderer.rb
|
171
|
+
- examples/rails5_app/config/initializers/assets.rb
|
172
|
+
- examples/rails5_app/config/initializers/backtrace_silencers.rb
|
173
|
+
- examples/rails5_app/config/initializers/cookies_serializer.rb
|
174
|
+
- examples/rails5_app/config/initializers/devise.rb
|
175
|
+
- examples/rails5_app/config/initializers/filter_parameter_logging.rb
|
176
|
+
- examples/rails5_app/config/initializers/inflections.rb
|
177
|
+
- examples/rails5_app/config/initializers/mime_types.rb
|
178
|
+
- examples/rails5_app/config/initializers/new_framework_defaults.rb
|
179
|
+
- examples/rails5_app/config/initializers/session_store.rb
|
180
|
+
- examples/rails5_app/config/initializers/wrap_parameters.rb
|
181
|
+
- examples/rails5_app/config/locales/devise.en.yml
|
182
|
+
- examples/rails5_app/config/locales/en.yml
|
183
|
+
- examples/rails5_app/config/puma.rb
|
184
|
+
- examples/rails5_app/config/routes.rb
|
185
|
+
- examples/rails5_app/config/secrets.yml
|
186
|
+
- examples/rails5_app/config/spring.rb
|
187
|
+
- examples/rails5_app/db/migrate/20170307140813_devise_create_users.rb
|
188
|
+
- examples/rails5_app/db/migrate/20170307145547_add_password_salt_to_users.rb
|
189
|
+
- examples/rails5_app/db/schema.rb
|
190
|
+
- examples/rails5_app/db/seeds.rb
|
191
|
+
- examples/rails5_app/lib/assets/.keep
|
192
|
+
- examples/rails5_app/lib/tasks/.keep
|
193
|
+
- examples/rails5_app/log/.keep
|
194
|
+
- examples/rails5_app/public/404.html
|
195
|
+
- examples/rails5_app/public/422.html
|
196
|
+
- examples/rails5_app/public/500.html
|
197
|
+
- examples/rails5_app/public/apple-touch-icon-precomposed.png
|
198
|
+
- examples/rails5_app/public/apple-touch-icon.png
|
199
|
+
- examples/rails5_app/public/favicon.ico
|
200
|
+
- examples/rails5_app/public/robots.txt
|
201
|
+
- examples/rails5_app/test/controllers/.keep
|
202
|
+
- examples/rails5_app/test/fixtures/.keep
|
203
|
+
- examples/rails5_app/test/fixtures/files/.keep
|
204
|
+
- examples/rails5_app/test/helpers/.keep
|
205
|
+
- examples/rails5_app/test/integration/.keep
|
206
|
+
- examples/rails5_app/test/mailers/.keep
|
207
|
+
- examples/rails5_app/test/models/.keep
|
208
|
+
- examples/rails5_app/test/test_helper.rb
|
209
|
+
- examples/rails5_app/tmp/.keep
|
210
|
+
- examples/rails5_app/vendor/assets/javascripts/.keep
|
211
|
+
- examples/rails5_app/vendor/assets/stylesheets/.keep
|
212
|
+
- gemfiles/rails_4_2.gemfile
|
213
|
+
- gemfiles/rails_5_0.gemfile
|
214
|
+
- gemfiles/rails_5_1.gemfile
|
75
215
|
- lib/devise/multi_email.rb
|
216
|
+
- lib/devise/multi_email/association_manager.rb
|
217
|
+
- lib/devise/multi_email/email_model_extensions.rb
|
218
|
+
- lib/devise/multi_email/email_model_manager.rb
|
76
219
|
- lib/devise/multi_email/models/authenticatable.rb
|
77
220
|
- lib/devise/multi_email/models/confirmable.rb
|
78
221
|
- lib/devise/multi_email/models/validatable.rb
|
222
|
+
- lib/devise/multi_email/parent_model_extensions.rb
|
223
|
+
- lib/devise/multi_email/parent_model_manager.rb
|
79
224
|
- lib/devise/multi_email/version.rb
|
80
225
|
homepage: https://github.com/allenwq/devise-multi_email.git
|
81
226
|
licenses:
|