Пример #1
0
 /**
  * Client object as an array
  *
  * @return     array  Client object as an array
  */
 public function __toArray() : array
 {
     return ['id' => $this->id, 'connection' => $this->connection->getRemoteAddress() . ':' . $this->connection->getRemotePort(), 'user' => $this->user !== null ? $this->user->__toArray() : [], 'location' => $this->location];
 }
Пример #2
0
 /**
  * Determine if the user has room edit right
  *
  * @param      Room  $room   The room to check in
  *
  * @return     bool  True if the user has room edit right, false otherwise
  */
 public function hasRoomEditRight(Room $room) : bool
 {
     $userEntityManager = new UserEntityManager($this->user, $this->userCollection);
     return $userEntityManager->checkSecurityToken() && ($this->user->getRight()->chatAdmin || $this->user->getRoomRight()->getEntityById($room->id) !== null && $this->user->getRoomRight()->getEntityById($room->id)->edit);
 }
Пример #3
0
 /**
  * Insert users in database
  */
 private function insertUserData()
 {
     $users = new UserCollection();
     $userManager = new UserManager(null, $users);
     $password = crypt('123', Ini::getParam('User', 'passwordCryptSalt'));
     static::out('Create user data' . PHP_EOL);
     // Create an admin with password = 123
     $admin = new User(['id' => 1, 'email' => '*****@*****.**', 'firstName' => 'Admin', 'lastName' => 'God', 'pseudonym' => 'admin', 'password' => $password]);
     $admin->setRight(new UserRight(['idUser' => 1, 'webSocket' => 1, 'chatAdmin' => 1, 'kibana' => 1]));
     $users->add($admin);
     // Create some normal users with password = 123
     for ($i = 1; $i < 11; $i++) {
         $user = new User(['id' => $i + 1, 'email' => 'user_' . $i . '@websocket.com', 'firstName' => 'User ' . $i, 'lastName' => 'Normal', 'pseudonym' => 'User ' . $i, 'password' => $password]);
         $users->add($user);
     }
     if ($userManager->saveUserCollection()) {
         static::ok(sprintf('The followings users are inserted %s' . PHP_EOL, $users));
     } else {
         static::fail('An error occurred on user collection save' . PHP_EOL);
     }
 }