用戶登錄後(ENV['warden'].authenticate!
'd)一次,warden
如何知道?除了rack.session
價值之外,我無法在cookie中找到任何內容 - 我無法從文檔或代碼中找出這些。監督員如何從機架會話中獲取當前用戶?
4
A
回答
0
在色器件/ LIB /色器件/控制器/ helpers.rb:35
def devise_group(group_name, opts={})
mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{group_name}!(favourite=nil, opts={})
unless #{group_name}_signed_in?
mappings = #{mappings}
mappings.unshift mappings.delete(favourite.to_sym) if favourite
mappings.each do |mapping|
opts[:scope] = mapping
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
end
end
def #{group_name}_signed_in?
#{mappings}.any? do |mapping|
warden.authenticate?(scope: mapping)
end
end
def current_#{group_name}(favourite=nil)
mappings = #{mappings}
mappings.unshift mappings.delete(favourite.to_sym) if favourite
mappings.each do |mapping|
current = warden.authenticate(scope: mapping)
return current if current
end
nil
end
def current_#{group_name.to_s.pluralize}
#{mappings}.map do |mapping|
warden.authenticate(scope: mapping)
end.compact
end
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
METHODS
end
https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb
闡釋: 在服務器開始時devise_group方法運行動態地創建輔助方法(CURRENT_USER例如),這是用於實際保存用戶的執事012xx的包裝,其內容是warden.authenticate方法內容是
def warden
request.env['warden']
end
也是在同一個文件中聲明
+1
如果你添加了一些關於你想用這段代碼片段傳達的信息將會很有幫助 –
相關問題
- 1. Erlang:誰來監督監督員?
- 2. 如何獲取當前記錄的用戶會話ID?
- 3. 使用TensorFlow監督員
- 4. 在java服務中獲取當前會話的用戶名
- 5. Django:如何獲取管理員表單中的當前用戶
- 6. 機架監督員:我如何訪問傳遞給失敗的消息!方法?
- 7. 如何獲取用戶當前國家電話區號前:+966
- 8. 從用戶會話jackrabbit獲取用戶
- 9. 會話超時時獲取用戶當前頁面
- 10. 獲取當前登錄用戶的會話 - 自定義頁面
- 11. Spree - 如何獲取當前登錄的管理員用戶
- 12. 受監督或無監督
- 13. Akka監督管理監督
- 14. 如何使用MapperFactoryBean獲取當前會話?
- 15. jQuery獲取當前會話的請求
- 16. Nette Framework - 獲取當前會話ID
- 17. 如何獲取當前用戶目錄?
- 18. 如何獲取當前用戶名?
- 19. 如何獲取用戶當前位置
- 20. 從mysql查詢中獲取當前會話/進程ID
- 21. 從當前會話中獲取名字PHP
- 22. 如何從AEM中的複製事件獲取用戶會話?
- 23. 從Google Analytics Cookie獲取當前用戶/會話綜合瀏覽量?
- 24. 如何從spring安全中獲取當前用戶角色3.1
- 25. 如何在hibernate事件監聽器中獲取當前登錄用戶
- 26. 從根模式獲取當前用戶?
- 27. 從CouchDB獲取當前用戶信息?
- 28. 從BlobstoreUploadHandler獲取當前用戶
- 29. 在會話超時後在當前頁面上獲取會話
- 30. 如何管理客戶端的當前用戶會話?
你能詳細說明一下這個問題嗎? 'env ['rack.session']'包含這個特定用戶的會話,並且包含一個'warden.user.key'或者其他東西... – mhutter
@mhutter但是服務器上存儲的是哪裏?這似乎是在這裏統一(https://github.com/rack/rack/blob/master/lib/rack/session/cookie.rb),但我無法找到它的存儲位置。似乎有兩個選項:Memcached和Pooled,但找不到哪一個是默認的,哪個是在什麼時候使用的。我知道它在服務器關閉後仍然存在,所以memcached? – Cenoc
你確定它會一直重新啓動嗎?默認是'Pool',它將數據存儲在'Hash'中:https://github.com/rack/rack/blob/master/lib/rack/session/pool.rb#L33 – mhutter