Skip to content

Anon support #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions discuss/web/channels/user_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ defmodule Discuss.UserSocket do
transport :websocket, Phoenix.Transports.WebSocket

def connect(%{"token" => token}, socket) do
case Phoenix.Token.verify(socket, "key", token) do
{:ok, user_id} ->
{:ok, assign(socket, :user_id, user_id)}
{:error, _error} ->
:error
if token == "undefined" do
{:ok, socket} # anonymous
else
case Phoenix.Token.verify(socket, "key", token) do
{:ok, user_id} ->
{:ok, assign(socket, :user_id, user_id)}
{:error, _error} ->
:error
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion discuss/web/templates/topic/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<li class="collection-item">
<%= link topic.title, to: topic_path(@conn, :show, topic) %>

<%= if @conn.assigns.user.id == topic.user_id do %>
<%= if @conn.assigns.user && @conn.assigns.user.id == topic.user_id do %>
<div class="right">
<%= link "Edit", to: topic_path(@conn, :edit, topic) %>
<%= link "Delete", to: topic_path(@conn, :delete, topic), method: :delete %>
Expand Down