allenwq / devise-multi_email Goto Github PK
View Code? Open in Web Editor NEW✉️ Let devise support multiple emails (authenticatable, confirmable and validatable).
License: MIT License
✉️ Let devise support multiple emails (authenticatable, confirmable and validatable).
License: MIT License
I can't register new user. I always get the Emails is invalid
error.
I do not know the level of effort involved in pushing out a new release, but I'd love to see a new version of this gem show up as HEAD includes fixes that would remove a deprecation warning in rails 6 and (presumably) allow it to continue to function in later versions. I'll gladly help out with the release if it is a matter of time available.
Currently, devise mailer sends the reset password instructions email to the resource email:
https://github.com/heartcombo/devise/blob/29943a26e61d68198666c59e07457dba3c75f581/lib/devise/mailers/helpers.rb#L34
But with multiple emails, you might want to get the reset password instructions to the email you entered, regardless of whether it's your primary email or not, right? In that case the email to should be set to opts[:email]
instead.
Should we override this method? Is that something we are interested in doing?
Email validation always returns Email is invalid
even when the email "has already been taken" (uniqueness validation).
Email validation should show "has already been taken"
Hi,
Just wanted to confirm that the names of the models should necessariy be User and Emails ?
I created a model called "Team" and "Email" and when I create an email, I get an exception
Email: Association :user not found: Have you declared that ?
I wrote an initializer like suggested on the readme:
# config/initializers/devise-multi_email.rb
Devise::MultiEmail.configure do |config|
config.emails_association_name = :user_emails
# Default is :primary_email_record
# config.primary_email_method_name = :primary_email
end
I'm using the following version in the gemfile, that I got from rubygems:
gem 'devise-multi_email', '~> 1.0', '>= 1.0.2'
And I get
Undefined method
configure' for Devise::MultiEmail:Module (NoMethodError)`
Now for later versions like 2.0 it works fine, but it is not the one on Rubygems
this line in the confirmable.rb
model file needs to be updated to sync up with the newly configurable primary_email_method_name
:
instead of
... to: :primary_email_record ...
it should be changed to
... to: Devise::MultiEmail.primary_email_method_name ...
if your method name is primary_email
as is now recommended, then that line throws this error:
undefined local variable or method `primary_email_record' for #<User:0x00...>
changing it as above makes the error go away.
Arise from #10, devise-encryptable
must be declared after multi-email in the Gemfile.
To investigate why.
The following part of the README:
The [Devise README](https://github.com/plataformatec/devise#activejob-integration) describes how to use ActiveJob to deliver emails in the background. Normally you would place the following code in your `User` model, however when using _devise-multi_email_ you should place this in the `Email` model.
does not seem to be correct. If I put the method send_devise_notification
on the Email model, the debugger does not hit it. If I place it on the User
model, the debugger stops. Should we drop this part of the README?
To support Rails 6.x, add something like a gemfiles/rails6.gemfile
?
Is it possible to access user record attributes like username, name to be used in the confirmation email?
I have a data model where multiple objects can have emails, so my Email class has a polymorphic :owner rather than a belongs_to :user
association (as illustrated below). in my preliminary tests, i was pleasantly surprised to find that devise and devise-multi_email mostly worked out-of-the-box for this use case (:invitable
breaks and found a separate bug (#18)). is this a use case that's officially supported (in which case it would be nice to see it mentioned in the documentation) or do i need to be on the lookout for breakages?
# app/models/user.rb
class User < ApplicationRecord
has_many :emails, as: :owner
devise :multi_email_authenticatable, ...
...
end
# app/models/email.rb
class Email < ApplicationRecord
belongs_to :owner, polymorphic: true, optional: true
...
end
thanks!
I'm trying to migrate from a functional devise+omniauth+devise-multi-email install to bring in devise_token_auth but I seem to be running into a problem between devise-multi_email and devise_token_auth. I've submitted an issue to them, but I'm wondering if you might be able to verify that my understanding is correct and let me know if a change should be made here or there?
Rails 6.1 deprecated errors.keys
and instead recommends errors.attribute_names
.
validatable.rb
uses errors.keys
directly and ought to use errors.attribute_names
when in Rails 6+.
Hi,
I just added multi email gem and facing with 2 problem atm.
1 - After move all email to new table, i try to login and got another error
BCrypt::Errors::InvalidHash at /users/sign_in
invalid hash
2- After submit new user, i got this error
NoMethodError at /users undefined method
limit' for nil:NilClass`
at this line user.valid?
in user model, i have no email validates but validates :email, uniqueness: true
I did everything exactly like Readme. Where did i go wrong?
edfb595 was 3.0.0, the gem release.
It would be cool and useful to have a Git tag there.
I used this method to migrate my emails from the email
field to the emails
table:
def update_emails
existing_email = self.read_attribute_before_type_cast('email')
if email == nil && existing_email != ''
email = Email.new(email: existing_email, user: self, primary: true)
email.skip_confirmation!
email.save
if email.errors.present?
return errors
end
logger.info 'Email Updated!'
else
logger.info 'Email already exists or no email saved on record'
end
end
In Rails console:
User.find_each(&:update_emails)
Perhaps we could include this in the readme?
If a user has 2 emails, how can they change their primary email?
I tried to do the following:
@email.primary = true
@email.save
This does work, however, the original primary email remains as a primary email record. Could we add validations to ensure that a user has only one primary email?
Should use multiple Gemfiles and let travis pickup different one in different group
find_first_by_auth_conditions
deletes the email from the tainted_conditions
hash, so it doesn't go to devise_parameter_filter
for downcasing.
The suggestion below works for case insensitive login but has not been tested in other scenarios.
def find_first_by_auth_conditions(tainted_conditions, opts = {})
tainted_conditions = tainted_conditions.dup
email = tainted_conditions[:email]
if email && email.is_a?(String)
conditions = devise_parameter_filter.filter(tainted_conditions).to_h.merge(opts)
conditions = { emails: conditions }
resource = joins(:emails).find_by(conditions)
resource.current_login_email = email if resource.respond_to?(:current_login_email=)
resource
else
super(tainted_conditions, opts)
end
end
References Coursemology/coursemology2#1292
Thanks for creating and maintaining this gem.
Travis is not building anymore on travis-ci.org. You may need to migrate to travis-ci.com and also update the README with the new badge.
Another solution would be moving to GitHub Actions, but should take longer to make it work.
The error message present on https://travis-ci.org/github/allenwq/devise-multi_email/builds:
Since June 15th, 2021, the building on travis-ci.org is ceased. Please use travis-ci.com from now on.
I have tried adding using devise-multi_email with association other than user.
getting undefined method `devise' for Email (call 'Email.connection' to establish a connection):Class (NoMethodError)
undefined method devise' for Email (call 'Email.connection' to establish a connection):Class (NoMethodError) from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:9:in
block in module:EmailConfirmable'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in class_eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in
append_features'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/association_manager.rb:14:in include' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/association_manager.rb:14:in
include_module'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:40:in block in <module:ConfirmableExtensions>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in
class_eval'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in append_features' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:29:in
include'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:29:in block in <module:MultiEmailConfirmable>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in
class_eval'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in append_features' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:103:in
include'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:103:in block (2 levels) in devise' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:87:in
each'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:87:in block in devise' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:114:in
devise_modules_hook!'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:84:in devise' from /home/shruti/api_v3/app/models/fields/fields_talent.rb:48:in
block in included'
from /home/shruti/api_v3/app/models/fields/fields_talent.rb:5:in class_eval' from /home/shruti/api_v3/app/models/fields/fields_talent.rb:5:in
included'
from /home/shruti/api_v3/app/models/talent.rb:12:in include' from /home/shruti/api_v3/app/models/talent.rb:12:in
class:Talent'
from /home/shruti/api_v3/app/models/talent.rb:2:in <top (required)>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:476:in
load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:476:in block in load_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:661:in
new_constants_in'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:475:in load_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:374:in
block in require_or_load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:36:in block in load_interlock' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:12:in
block in loading'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:149:in exclusive' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:11:in
loading'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:36:in load_interlock' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:357:in
require_or_load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:510:in load_missing_constant' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:202:in
const_missing'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in const_get' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in
block in constantize'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in
inject'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in constantize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:582:in
get'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:613:in constantize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:313:in
get'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:81:in to' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:76:in
modules'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:93:in routes' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:160:in
default_used_route'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:70:in initialize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:343:in
new'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:343:in add_mapping' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:241:in
block in devise_for'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in
devise_for'
from (eval):1:in draw' from /home/shruti/api_v3/config/routes.rb:3:in
instance_eval'
from /home/shruti/api_v3/config/routes.rb:3:in draw' from /home/shruti/api_v3/config/routes.rb:9:in
block in <top (required)>'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in instance_exec' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in
eval_block'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:408:in draw' from /home/shruti/api_v3/config/routes.rb:7:in
<top (required)>'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in load' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in
block in load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in load_dependency' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in
load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in block in load_paths' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in
each'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in load_paths' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:18:in
reload!'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:41:in block in updater' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/file_update_checker.rb:81:in
execute'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:42:in updater' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:31:in
execute_if_updated'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/finisher.rb:128:in block in <module:Finisher>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:30:in
instance_exec'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:30:in run' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:59:in
block in run_initializers'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:228:in block in tsort_each' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:350:in
block (2 levels) in each_strongly_connected_component'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:431:in each_strongly_connected_component_from' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:349:in
block in each_strongly_connected_component'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in each' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in
call'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in each_strongly_connected_component' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:226:in
tsort_each'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:205:in tsort_each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:58:in
run_initializers'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application.rb:353:in initialize!' from /home/shruti/api_v3/config/environment.rb:5:in
<top (required)>'
from config.ru:1:in require_relative' from config.ru:1:in
block in
instance_eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:55:in
initialize'new' from config.ru:in
'eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:49:in
new_from_string'parse_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/server.rb:319:in
build_app_and_options_from_config'app' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in
app'wrapped_app' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in
log_to_stdout'start' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in
block in perform'tap' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in
perform'run' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/thor-0.20.0/lib/thor/invocation.rb:126:in
invoke_command'dispatch' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/command/base.rb:63:in
perform'invoke' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands.rb:16:in
<top (required)>'One of the files is lacking test coverage lib/devise/multi_email/email_model_manager.rb
.
This Issue is successful if we add a test which shows that:
#parent
delegates into the @email_record
's configured multi_email_association.name
See related Devise issue by the same name. The fix appears to be possible in lib/devise/multi_email/models/validatable.rb and I'm working on a pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.