diff options
author | Alex Auvolat <alex@adnab.me> | 2018-10-12 14:40:21 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-10-12 14:40:21 +0200 |
commit | 1e91dc596fd2f7fdd96b7fd2fc50724f93e46529 (patch) | |
tree | 067d56e6fb9e215cc76dea5c9c82e61ef369d90e /shardweb/lib/controllers/identity_controller.ex | |
parent | d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 (diff) | |
download | shard-1e91dc596fd2f7fdd96b7fd2fc50724f93e46529.tar.gz shard-1e91dc596fd2f7fdd96b7fd2fc50724f93e46529.zip |
Move and reorganize some stuff
Diffstat (limited to 'shardweb/lib/controllers/identity_controller.ex')
-rw-r--r-- | shardweb/lib/controllers/identity_controller.ex | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/shardweb/lib/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex new file mode 100644 index 0000000..fdaefd0 --- /dev/null +++ b/shardweb/lib/controllers/identity_controller.ex @@ -0,0 +1,44 @@ +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 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 |