defmodule ShardWeb.IdentityController do
use ShardWeb, :controller
def view(conn, _params) do
render conn, "view.html"
end
def update(conn, params) do
pid = SApp.Identity.find_proc(conn.assigns.pk)
info = GenServer.call(pid, :get_info)
info = %{info | nick: params["nick"]}
GenServer.call(pid, {:set_info, info})
redirect conn, to: identity_path(conn, :view)
end
def switch(conn, params) do
case Base.decode16(params["pk"]) do
{:ok, pk} ->
if Shard.Keys.have_sk? pk do
conn
|> put_session(:pk, pk)
|> redirect(to: identity_path(conn, :view))
else
conn
|> put_flash(:error, "No secret key found")
|> render("view.html")
end
_ ->
conn
|> put_flash(:error, "Bad argument")
|> render("view.html")
end
end
def create(conn, _params) do
pk = Shard.Keys.new_identity
conn = put_session(conn, :pk, pk)
redirect conn, to: identity_path(conn, :view)
end
end