Skip to content

Commit

Permalink
Added Byebug
Browse files Browse the repository at this point in the history
  • Loading branch information
namangupta01 committed Jun 25, 2019
1 parent 88cea8a commit 55691b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end

def find_verified_user
if cookies.signed['user_token'] != nil
user = User.where(persistence_token: cookies.signed['user_token'])
if user.any?
return user.first
else
return nil
end
else
return nil
end
end
end
end
5 changes: 4 additions & 1 deletion app/channels/room_channel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is a general channel connected to all active session
class RoomChannel < ApplicationCable::Channel

def subscribed
stream_from "room_channel"
end
Expand All @@ -9,6 +10,8 @@ def unsubscribed
end

def speak(message)
ActionCable.server.broadcast 'room_channel', message
if current_user && current_user.role == "admin"
ActionCable.server.broadcast 'room_channel', message
end
end
end
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def current_user
# Ensures no code will use old @current_user info. Treat the user
# as anonymous (until the login process sets @current_user again):
@current_user = nil

end

cookies.signed["user_token"] = nil
if @current_user
cookies.signed["user_token"] = @current_user.role
end
@current_user
end
Expand All @@ -102,6 +108,7 @@ def require_user
redirect_to login_url
false
end
return current_user
end

def require_no_user
Expand Down

0 comments on commit 55691b2

Please sign in to comment.