【问题标题】:Devise/Devise_invitable: How to skip the pending invitations controlDevise/Devise_invitable:如何跳过待处理的邀请控件
【发布时间】:2015-08-24 20:17:55
【问题描述】:

我有一个使用 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

谢谢!

【问题讨论】:

    标签: ruby-on-rails devise devise-invitable


    【解决方案1】:

    好的,我在已打开的 devise_invitable ticket 获得了帮助。

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

    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
    

    希望以后能对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多