Rails Gem Devise是否有解决方案允许用户拥有多个电子邮件? [英] Is there a solution for Rails Gem Devise to allow a user to have multiple emails?

查看:96
本文介绍了Rails Gem Devise是否有解决方案允许用户拥有多个电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个解决方案,让我的应用上的用户拥有超过1封电子邮件。这应该类似于Facebook,LinkedIn和Quora。帐户可以有多个电子邮件,1个作为主要邮件。

I'm looking for a solution to allow a user on my app to have more than 1 email. This should work similar to Facebook, LinkedIn and Quora. Where an account can have multiple emails, 1 as the primary.

有没有一个交钥匙解决方案的设计avaialble?我希望不要从头开始写这个,因为它很常见。

Is there a turn-key solution for devise avaialble? I'm hoping to not have to write this from scratch given it's so common.

想法?谢谢

推荐答案

嗯...我建议创建新的模型,你会做这样的事情:

Hm...I'll suggest to create new model, You'll do something like this:

例如,模型将是 UserEmail

class UserEmail < ActiveRecord::Base
    belongs_to :user
end

class User < ActiveRecord::Base
    has_many :user_emails
end

并覆盖devise的方法在中找到记录用户模型:

and override devise's method to find record in User model:

def self.find_first_by_auth_conditions(warden_conditions)
  conditions = warden_conditions.dup
  if email = conditions.delete(:email)
    User.includes(:user_emails).where('user_emails.email = ?', email).first
  else
    super(warden_conditions)
  end

了解更多关于覆盖这里: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

Read more about override here: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

这篇关于Rails Gem Devise是否有解决方案允许用户拥有多个电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆