diff options
author | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
commit | 1a13285971ef728109011a93e676e26248b30242 (patch) | |
tree | f03467bc07ff84961f8c3eb88497adaf36b5f009 /shardweb/lib/shard_web/channels | |
parent | 7d0009d83c9b5c747d4adb535817924762429f30 (diff) | |
download | shard-1a13285971ef728109011a93e676e26248b30242.tar.gz shard-1a13285971ef728109011a93e676e26248b30242.zip |
Fixes
Diffstat (limited to 'shardweb/lib/shard_web/channels')
-rw-r--r-- | shardweb/lib/shard_web/channels/room_channel.ex | 1 | ||||
-rw-r--r-- | shardweb/lib/shard_web/channels/user_socket.ex | 16 |
2 files changed, 14 insertions, 3 deletions
diff --git a/shardweb/lib/shard_web/channels/room_channel.ex b/shardweb/lib/shard_web/channels/room_channel.ex index 2935c45..f582e06 100644 --- a/shardweb/lib/shard_web/channels/room_channel.ex +++ b/shardweb/lib/shard_web/channels/room_channel.ex @@ -16,7 +16,6 @@ defmodule ShardWeb.RoomChannel do pid end socket = assign(socket, :pid, pid) - socket = assign(socket, :pk, Shard.Keys.get_any_identity) # TODO same as in session! GenServer.cast(pid, {:subscribe, self()}) send(self(), :after_join) diff --git a/shardweb/lib/shard_web/channels/user_socket.ex b/shardweb/lib/shard_web/channels/user_socket.ex index 4fb76dc..a3aa1a5 100644 --- a/shardweb/lib/shard_web/channels/user_socket.ex +++ b/shardweb/lib/shard_web/channels/user_socket.ex @@ -1,6 +1,8 @@ defmodule ShardWeb.UserSocket do use Phoenix.Socket + require Logger + ## Channels channel "room:*", ShardWeb.RoomChannel @@ -19,8 +21,18 @@ defmodule ShardWeb.UserSocket do # # See `Phoenix.Token` documentation for examples in # performing token verification on connect. - def connect(_params, socket) do - {:ok, socket} + def connect(params, socket) do + case Base.decode16(params["pk"]) do + {:ok, pk} -> + if Shard.Keys.have_sk? pk do + socket = assign(socket, :pk, pk) + {:ok, socket} + else + Logger.warn("Invalid pk at user_socket.connect... #{params["pk"]}") + :error + end + _ -> :error + end end # Socket id's are topics that allow you to identify all sockets for a given user: |