예제 #1
0
 /**
  * Handle the event.
  *
  * @param  \App\WS\Message $message
  * @param  \App\WS\Connection $conn
  * @return void
  */
 public function handle($message, $conn)
 {
     $request = Request::capture();
     $request->query->add(['code' => $message->data('code')]);
     $provider = $message->data('provider');
     $user = Socialite::driver($provider)->stateless()->setRequest($request)->user();
     if ($u = User::findByProvider($provider, $user->getId())) {
         return $this->send($message->from(), $message->event(), $u->setHidden([]));
     }
     if (User::where('email', $user->getEmail())->exists()) {
         return $this->send($message->from(), $message->event(), 'The email has already been taken.', 422);
     }
     $user = User::create(['name' => $user->getName(), 'email' => $user->getEmail(), 'avatar' => $user->getAvatar(), 'provider' => $provider, 'provider_id' => $user->getId(), 'api_token' => str_random(32)]);
     return $this->send($message->from(), $message->event(), $user->setHidden([]), 201);
 }
예제 #2
0
파일: Chat.php 프로젝트: edcoreweb/dominox
 /**
  * Handle the event.
  *
  * @param  \App\WS\Message $message
  * @param  \App\WS\Connection $conn
  * @return void
  */
 public function handle($message, $conn)
 {
     $clients = $conn->clients();
     foreach ($clients as $client) {
         if ($message->from() !== $client) {
             $this->send($client, $message->event(), $message->data());
         }
     }
 }
예제 #3
0
 /**
  * Handle the event.
  *
  * @param  \App\WS\Message $message
  * @param  \App\WS\Connection $conn
  * @return void
  */
 public function handle($message, $conn)
 {
     $url = Socialite::driver($message->data('provider'))->stateless()->redirect()->headers->get('Location');
     return $this->send($message->from(), $message->event(), $url);
 }
예제 #4
0
 /**
  * Handle the event.
  *
  * @param  \App\WS\Message $message
  * @param  \App\WS\Connection $conn
  * @return void
  */
 public function handle($message, $conn)
 {
     $user = User::findByToken($message->data('api_token'));
     return $this->send($message->from(), $message->event(), $user->setHidden([]));
 }
예제 #5
0
 /**
  * Determine if the user is authenticated.
  *
  * @param  \App\WS\Message $message
  * @return bool
  */
 protected function authenticated(Message $message)
 {
     if (in_array($message->event(), ['oauth.url', 'oauth.user', 'api_token'])) {
         return true;
     }
     return $message->user();
 }