2016-10-07 29 views
0

我正試圖給Phoenix寫一個小應用程序。我通過示例進行了身份驗證http://meatherly.github.io/2015/05/11/phoenixauthentication/phoenix authenticate current_user

我認爲一切都結束了,但我無法弄清楚如何使用current_user的數據。 如果我寫在控制器:

user = conn.assigns.current_user 
IO.inspect user 

我得到:

{:ok, 
%Myfiles.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, 
    encrypted_password: "$2b$12$KLDREZ08084BhHXrJR8EAuQinHn.X2X9OlfylelYiK5KSinlxfTii", 
    id: 1, inserted_at: #Ecto.DateTime<2016-10-07 21:28:51>, password: "123456", 
    password_confirmation: "123456", 
    updated_at: #Ecto.DateTime<2016-10-07 21:28:51>, username: "test"}} 

這不是地圖?如何離開這裏身份證?

回答

0

current_user是含有:ok元組和user struct.You可以得到id列是這樣的:

{:ok, user} = conn.assigns.current_user 
IO.inspect user.id 

你可以閱讀更多關於結構here