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/user_socket.ex | |
parent | 7d0009d83c9b5c747d4adb535817924762429f30 (diff) | |
download | shard-1a13285971ef728109011a93e676e26248b30242.tar.gz shard-1a13285971ef728109011a93e676e26248b30242.zip |
Fixes
Diffstat (limited to 'shardweb/lib/shard_web/channels/user_socket.ex')
-rw-r--r-- | shardweb/lib/shard_web/channels/user_socket.ex | 16 |
1 files changed, 14 insertions, 2 deletions
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: |