diff options
Diffstat (limited to 'shardweb/lib/controllers')
-rw-r--r-- | shardweb/lib/controllers/directory_controller.ex | 29 | ||||
-rw-r--r-- | shardweb/lib/controllers/identity_controller.ex | 34 |
2 files changed, 63 insertions, 0 deletions
diff --git a/shardweb/lib/controllers/directory_controller.ex b/shardweb/lib/controllers/directory_controller.ex new file mode 100644 index 0000000..1e3a0b0 --- /dev/null +++ b/shardweb/lib/controllers/directory_controller.ex @@ -0,0 +1,29 @@ +defmodule ShardWeb.DirectoryController do + use ShardWeb, :controller + + def view_pub(conn, %{"owner" => owner, "name" => name}) do + owner = Base.decode16! owner + shard = %SApp.Directory.Manifest{public: true, owner: owner, name: name} + pid = Shard.Manager.find_or_start shard + + render conn, "view.html", + public: true, + shard: shard, + pid: pid, + owner: owner, + name: name + end + + def view_priv(conn, %{"owner" => owner, "name" => name}) do + owner = Base.decode16! owner + shard = %SApp.Directory.Manifest{public: false, owner: owner, name: name} + pid = Shard.Manager.find_or_start shard + + render conn, "view.html", + public: false, + shard: shard, + pid: pid, + owner: owner, + name: name + end +end diff --git a/shardweb/lib/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex index 962a888..d1c6886 100644 --- a/shardweb/lib/controllers/identity_controller.ex +++ b/shardweb/lib/controllers/identity_controller.ex @@ -25,6 +25,40 @@ defmodule ShardWeb.IdentityController do end end + def view_post(conn, opts) do + IO.puts(inspect opts) + {:ok, pk} = Base.decode16(opts["pk"]) + manifest = %SApp.Identity.Manifest{pk: pk} + nick = SApp.Identity.get_nick pk + shard = manifest |> SData.term_hash + pid = Shard.Manager.find_proc shard + + if opts["add_friend"] == "true" do + friend_list = SApp.Directory.friends_dir(conn.assigns.pk) + name = nick <> " " <> Shard.Keys.pk_display(pk) + SApp.Directory.add_file(friend_list, name, manifest) + end + + if opts["rm_friend"] == "true" do + friend_list = SApp.Directory.friends_dir(conn.assigns.pk) + name = SApp.Directory.find(friend_list, manifest) + if name != nil do + SApp.Directory.rm_file(friend_list, name) + end + end + + if pid == nil do + render conn, ShardWeb.ErrorView, "404.html" + else + render conn, "view.html", + view_pk: pk, + view_nick: SApp.Identity.get_nick(pk), + shard: shard, + pid: pid + end + #TODO + end + def update(conn, params) do pid = SApp.Identity.find_proc(conn.assigns.pk) info = SApp.Identity.get_info(pid) |