代码之家  ›  专栏  ›  技术社区  ›  Saw Thinkar Nay Htoo Lavekush Agrawal

在菲尼克斯处理过期会话

  •  0
  • Saw Thinkar Nay Htoo Lavekush Agrawal  · 技术社区  · 8 年前

    我想知道如何防止请求过期会话时出现此错误。有什么好办法可以做到这一点?我检查过了 Custom Errors ,但不确定有多大帮助。

    enter image description here

    • 首先,在会话中创建并设置uuid。

      uuid = SecureRandom.uuid
      SessionStore.set uuid, id, ttl: 20
      
    • 然后将下面的url链接发送给用户,当用户单击时,它应该检查uuid是否在会话中过期。

      <% verify_url = MyAppWeb.Router.Helpers.email_url(MyAppWeb.Endpoint, :verify, uuid: @uuid) %>
      
    • Uuid被选中

      def verify(conn, %{"uuid" => uuid}) do
          user_id = SessionStore.get(uuid)
      end
      
    1 回复  |  直到 8 年前
        1
  •  0
  •   Saw Thinkar Nay Htoo Lavekush Agrawal    8 年前

    我只是先检查一下零值。我也可以使用中建议的案例 here .

    if SessionStore.get(uuid) == nil do
      IO.puts "uuid expired"
    else
      user_id = SessionStore.get(uuid)
      user = Accounts.get_user!(user_id)
    end