Created
May 5, 2016 06:07
-
-
Save Fadhil/d1536c52a0f8eeb9d66a3ea9a72a7590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plug.AnonymousSessionStore do | |
@behaviour Plug.Session.Store | |
def init(_opts) do | |
nil | |
end | |
def get(_conn, sid, nil) do | |
{sid, Process.get({:session, sid}) || %{}} | |
end | |
def delete(_conn, sid, nil) do | |
Process.delete({:session, sid}) | |
:ok | |
end | |
def put(conn, nil, data, nil) do | |
sid = :crypto.strong_rand_bytes(96) |> Base.encode64 | |
put(conn, sid, data, nil) | |
end | |
def put(_conn, sid, data, nil) do | |
Process.put({:session, sid}, data) | |
sid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment