1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
defmodule ShardWeb.IdentityController do
use ShardWeb, :controller
def list(conn, _params) do
render conn, "list.html"
end
def self(conn, _params) do
render conn, "self.html"
end
def view(conn, %{"pk" => pk}) do
#TODO
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, :self)
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, :self))
else
conn
|> put_flash(:error, "No secret key found")
|> render("self.html")
end
_ ->
conn
|> put_flash(:error, "Bad argument")
|> render("self.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, :self)
end
end
|