/**
  * @param string $userName
  *
  * @return WiseChatUser
  */
 private function createUserAndSave($userName)
 {
     WiseChatContainer::load('model/WiseChatUser');
     // construct username and user object:
     $user = new WiseChatUser();
     $user->setName($userName);
     $user->setSessionId($this->userSessionDAO->getSessionId());
     $user->setIp($this->getRemoteAddress());
     if ($this->options->isOptionEnabled('collect_user_stats', true)) {
         $this->fillWithGeoDetails($user);
     }
     // save user in DB and in the session:
     $this->usersDAO->save($user);
     $this->userSessionDAO->set(self::SESSION_KEY_USER_ID, $user->getId());
     return $user;
 }
Esempio n. 2
0
 /**
  * Sets text color for messages typed by the current user.
  *
  * @param string $color
  *
  * @throws Exception If an error occurred
  */
 public function setUserTextColor($color)
 {
     if (!$this->authentication->isAuthenticated()) {
         throw new Exception('Unsupported operation');
     }
     if ($color != 'null' && !preg_match("/^#[a-fA-F0-9]{6}\$/", $color)) {
         throw new Exception('Invalid color signature');
     }
     if ($color == 'null') {
         $color = '';
     }
     $user = $this->authentication->getUser();
     $user->setDataProperty('textColor', $color);
     $this->usersDAO->save($user);
     $this->userEvents->resetEventTracker('usersList');
     $this->actions->publishAction('setMessagesProperty', array('chatUserId' => $user->getId(), 'propertyName' => 'textColor', 'propertyValue' => $color));
 }