public function getJwt()
 {
     if (Auth::check()) {
         return Response::json(['token' => Jwt::encode(['id' => Auth::user()->id])], 200);
     }
     return Response::json(['message', 'You could not get your auth token, please try agian'], 400);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         $user = \App\Services\Jwt::decode(Input::get('token'));
         Auth::loginUsingId($user->id);
         if (Auth::user()) {
             return $next($request);
         }
     } catch (\Exception $e) {
         dd($e);
     }
     return Response::json(array('message' => 'We could not authenticate you.'), 401);
 }
 public function onMessage(ConnectionInterface $from, $msg)
 {
     $msg = json_decode($msg);
     echo "New message! ({$from->resourceId}) Channel: " . $msg->channel . " \n";
     switch ($msg->channel) {
         case 'auth':
             $user = Jwt::decode($msg->token);
             if (!array_key_exists($user->id, $this->clients)) {
                 $this->clients[$user->id] = $from;
             }
             break;
         case 'toast':
             if (array_key_exists($msg->id, $this->clients)) {
                 $this->clients[$msg->id]->send(json_encode(['channel' => 'toast', 'message' => $msg->message]));
             }
             break;
         case 'broadcast':
             foreach ($this->clients as $index => $conn) {
                 $conn->send(json_encode(['channel' => 'toast', 'message' => $msg->message]));
             }
             break;
         case 'subscribe':
             $this->onSubscribe($msg->id, $msg->topic);
             break;
         case 'unsubscribe':
             $this->onUnSubscribe($from, $msg->topic);
             break;
         case 'publish':
             if (isset($this->topics[$msg->topic])) {
                 foreach ($this->topics[$msg->topic] as $id) {
                     $conn = $this->clients[$id];
                     $msg = $this->getPublish($msg, $id);
                     $conn->send(json_encode(['channel' => $msg->topic, 'message' => $msg->html]));
                 }
             }
             break;
     }
 }
Пример #4
0
 public function getUser()
 {
     $token = Utils\Cookie::get('token');
     $tokenInfo = Jwt::decodeArray($token);
 }