2015-08-24 30 views
0

我有一個Rails/Mongoid應用程序,它使用devise和devise_invitable gems以及用戶has_and_belongs_to_many組的特殊場景。這在應用程序中意味着用戶可以被其他用戶邀請到一個或多個組。我正在使用devise_invitable來爲新用戶和現有用戶處理這些邀請。Devise/Devise_invitable:如何跳過待處理的邀請控制

我遇到問題的場景是,已經註冊並確認其帳戶並且可能已經被邀請加入一個組的用戶被邀請加入其他組。在這種情況下,系統會像往常一樣發送新邀請,但是會爲現有用戶發送新邀請,而不是創建新邀請。

如果用戶確認邀請一切正常,但我遇到的問題是,除非用戶確認,否則他/她將不能再次登錄到他的用戶帳戶,因爲它會得到警報:

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

所以我不知道我應該怎麼做或者我應該以跳過試圖登錄,已經被證實,但有一個待處理邀請用戶時控制在設計/ 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 

謝謝!

回答

0

好的我在devise_invitable ticket已經打開了。

實現我所要求的方法是在用戶模型上覆蓋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 

希望幫助任何人在未來的人。

相關問題