示例#1
0
 /**
  * Creates or updates the channel and returns it.
  *
  * @param WiseChatChannel $channel
  *
  * @return WiseChatChannel
  * @throws Exception On validation error
  */
 public function save($channel)
 {
     global $wpdb;
     // low-level validation:
     if ($channel->getName() === null) {
         throw new Exception('Name of the channel cannot equal null');
     }
     // prepare channel data:
     $table = WiseChatInstaller::getChannelsTable();
     $columns = array('name' => $channel->getName(), 'password' => $channel->getPassword());
     // update or insert:
     if ($channel->getId() !== null) {
         $wpdb->update($table, $columns, array('id' => $channel->getId()), '%s', '%d');
     } else {
         $wpdb->insert($table, $columns);
         $channel->setId($wpdb->insert_id);
     }
     return $channel;
 }
示例#2
0
 /**
  * Authorizes the current user in the given channel.
  *
  * @param WiseChatChannel $channel
  * @param string $password
  *
  * @return boolean
  */
 public function authorize($channel, $password)
 {
     if ($channel->getPassword() === md5($password)) {
         $this->authorization->markAuthorizedForChannel($channel);
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * @param WiseChatChannel $channel
  * @throws WiseChatUnauthorizedAccessException
  */
 private function checkChannelAuthorization($channel)
 {
     if ($channel !== null && strlen($channel->getPassword()) > 0 && !$this->authorization->isUserAuthorizedForChannel($channel)) {
         throw new WiseChatUnauthorizedAccessException('Not authorized in this channel');
     }
 }