1
A
回答
0
你可以在ApplicationController中驗證這一點,如:
before_action :validate_user_role
...
def validate_user_role
flash[:alert] == "User don't have a Role"
redirect_to login_path if current_user.role.blank?
end
...
3
一種方式有條件地允許用戶登錄是通過覆蓋設計的#active_for_authentication?
方法:
class User < ActiveRecord::Base
def active_for_authentication?
super && role.present?
end
end
希望這有助於!
相關問題
- 1. PostgreSQL:角色不允許登錄
- 2. 只允許特定用戶角色登錄WordPress網站
- 3. 使用Rails Devise,允許與SAML同時使用用戶名/密碼登錄
- 4. 不要允許用戶多次登錄
- 5. Facebook PHP SDK不允許登錄用戶
- 6. Rails - Devise - 用戶登錄條紋
- 7. 可能的插件不允許某些用戶角色登錄,直到付款
- 8. PG :: ConnectionBad致命錯誤:角色「BetBook3」不允許登錄
- 9. JSP登錄用戶角色
- 10. 檢測,如果Facebook的用戶使用登錄按鈕允許或不允許登錄
- 11. 登錄 - 不同的用戶角色
- 12. 允許用戶更改角色
- 13. 只允許postgres用戶列表角色
- 14. Sitecore:允許用戶/角色發佈
- 15. 僅限Facebook登錄按鈕(不允許新用戶登錄)
- 16. 允許用戶在Devise中創建其他用戶嗎?
- 17. Ruby on Rails CanCan,允許用戶在註冊時選擇角色
- 18. 允許root用戶登錄ftp
- 19. 只允許在用戶登錄
- 20. 允許Wordpress用戶多登錄
- 21. web.config的角色和用戶名是否允許空格?
- 22. 允許詹金斯用戶將角色分配給其他人
- 23. Rails:水豚不能使用Devise夾具數據登錄用戶
- 24. 用Devise + Active Admin + Switch登錄其他用戶的帳戶用戶
- 25. 如何在Laravel 5.4中允許基於角色的登錄?
- 26. Rails pundit gem,允許查看非登錄用戶
- 27. Rails Devise - 通過URL登錄
- 28. fuelphp oil migrate允許字段爲空
- 29. 爲什麼技術角色用戶無法登錄developer.apple.com?
- 30. 允許用戶通過Google+登錄Spring Security應用程序登錄或OAuth 2.0