用戶註冊後,我想將他們引導到他們的儀表板。他們需要確認他們的電子郵件的完整功能。Rails&Devise:需要用戶確認特定功能的電子郵件,但允許他們在確認之前登錄
現在,當我添加:可確認到用戶模型時,用戶無法登錄。
我該如何實現此功能?
用戶註冊後,我想將他們引導到他們的儀表板。他們需要確認他們的電子郵件的完整功能。Rails&Devise:需要用戶確認特定功能的電子郵件,但允許他們在確認之前登錄
現在,當我添加:可確認到用戶模型時,用戶無法登錄。
我該如何實現此功能?
只是寫在devise.rb
config.allow_unconfirmed_access_for = nil
寫一個驗證的application.rb中
def is_confirmed?
if user_signed_in?
if current_user.confirmed?
return true
else
flash[:notice] = "You are not allow to view this page."
redirect_to dashboard_path # your dashboard path
end
end
end
使用您的位指示
before_action :is_confirmed?, except: [:dashbord]
我想你可以用色器件實現這一點,allowing-unconfirmed-access
只需添加extreamely長時間,讓他們登錄,然後就檢查用戶是否已確認電子郵件 - 告訴他們所有的儀表盤的內容,反之亦然。
或者你可以跳過:confirmable
驗證。
希望這會有所幫助。
退房此Wiki網頁https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users
#解決方案1 在devise.rb
像您可以配置:
config.allow_unconfirmed_access_for = nil
因此,這意味着用戶可以訪問沒有任何確認,但例如:
config.allow_unconfirmed_access_for = 1.hour
因此,他們可以在1小時內訪問UT確認
#方案2
# in User.rb
protected
def confirmation_required?
false
end
所以現在使用可以在不確認任何訪問,但我認爲解決的辦法#1更高效!