2

我有一个使用 devise 和 devise_invitable gem 的 Rails/Mongoid 应用程序,其中一个特殊场景是用户 has_and_belongs_to_many 组。这在应用程序中意味着用户可以被其他用户邀请到一个或多个组。我正在使用 devise_invitable 为新用户和现有用户处理这些邀请。

我遇到问题的情况是,当已经注册并确认其帐户并且可能已经被邀请到一个组的用户被邀请到另一个组时。在这种情况下,系统会像往常一样发送新邀请,但不会为现有用户创建新邀请。

如果用户确认邀请一切正常,但我遇到的问题是,除非用户确认,否则他/她将无法再次登录到他的用户帐户,因为它会收到警报:

You have a pending invitation, accept it to finish creating your account.

所以我想知道我应该怎么做或应该在 Devise/Devise_invitable 上覆盖什么,以便在尝试以已确认但有待处理邀请的用户身份登录时跳过该控件。

我的用户模型是这个:

class User
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic
  include Mongoid::Timestamps
  include Mongoid::Userstamp::User

  devise :invitable, :encryptable, :database_authenticatable, :registerable, :lockable, :recoverable, :confirmable, :rememberable, :trackable, :validatable, :timeoutable

has_and_belongs_to_many :groups

谢谢!

4

1 回答 1

1

好的,我在我打开的 devise_invitable票上得到了帮助。

实现我所要求的方法是在 User 模型上覆盖此方法。因此,即使他/她有待处理的邀请,也允许已确认用户登录的解决方案如下:

class User
  ...
  def block_from_invitation?
    #If the user has not been confirmed yet, we let the usual controls work
    if confirmed_at.blank?
      return invited_to_sign_up?
    else #if the user was confirmed, we let them in (will decide to accept or decline invitation from the dashboard)
      return false
    end
  end
  ...
end

希望在未来对其他人有所帮助。

于 2015-08-26T12:28:20.777 回答