aboutsummaryrefslogtreecommitdiff
path: root/shardweb/lib/shard_web/router.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-09-26 18:14:32 +0200
committerAlex Auvolat <alex@adnab.me>2018-09-26 18:14:32 +0200
commit26629dc30a116204263ac4b515600649ba742ba0 (patch)
treea066688ce44e028abd188867bc92b72496d4893a /shardweb/lib/shard_web/router.ex
parent1a13285971ef728109011a93e676e26248b30242 (diff)
downloadshard-26629dc30a116204263ac4b515600649ba742ba0.tar.gz
shard-26629dc30a116204263ac4b515600649ba742ba0.zip
Web UI for multiple identities
Diffstat (limited to 'shardweb/lib/shard_web/router.ex')
-rw-r--r--shardweb/lib/shard_web/router.ex27
1 files changed, 25 insertions, 2 deletions
diff --git a/shardweb/lib/shard_web/router.ex b/shardweb/lib/shard_web/router.ex
index 180ebdd..4311a29 100644
--- a/shardweb/lib/shard_web/router.ex
+++ b/shardweb/lib/shard_web/router.ex
@@ -8,6 +8,7 @@ defmodule ShardWeb.Router do
plug :protect_from_forgery
plug :put_secure_browser_headers
plug Plug.Parsers, parsers: [:urlencoded]
+ plug :check_pk
end
pipeline :api do
@@ -18,13 +19,35 @@ defmodule ShardWeb.Router do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
- get "/room/:room", RoomController, :show
+ post "/peer/add", PageController, :add_peer
+
+ get "/identity", IdentityController, :view
+ post "/identity", IdentityController, :update
+ post "/identity/switch", IdentityController, :switch
+ post "/identity/create", IdentityController, :create
- post "/peer/add", PeerController, :add
+ get "/room/:room", RoomController, :show
end
# Other scopes may use custom stacks.
# scope "/api", ShardWeb do
# pipe_through :api
# end
+
+ def check_pk(conn, _kv) do
+ pk1 = get_session(conn, :pk)
+ {conn, pk} = if pk1 == nil || not Shard.Keys.have_sk? pk1 do
+ pk = Shard.Keys.get_any_identity
+ conn = put_session(conn, :pk, pk)
+ {conn, pk}
+ else
+ {conn, pk1}
+ end
+ nick = SApp.Identity.get_nick pk
+ conn
+ |> assign(:pk, pk)
+ |> assign(:nick, nick)
+ |> PhoenixGon.Controller.put_gon(pk: (pk|>Base.encode16))
+ end
+
end