/** * Marks the current user as authorized for given channel. * * @param WiseChatChannel $channel * * @return null */ public function markAuthorizedForChannel($channel) { $grants = $this->userSessionDAO->get(self::SESSION_KEY_USER_CHANNEL_AUTHORIZATION); if (!is_array($grants)) { $grants = array(); } $grants[$channel->getId()] = true; $this->userSessionDAO->set(self::SESSION_KEY_USER_CHANNEL_AUTHORIZATION, $grants); }
/** * Increments and returns abuses counter. * The counter is stored in user's session. * * @return integer */ public function incrementAndGetAbusesCounter() { $key = self::SESSION_KEY_ABUSES_COUNTER; $counter = 1; if ($this->userSessionDAO->contains($key)) { $counter += $this->userSessionDAO->get(self::SESSION_KEY_ABUSES_COUNTER); } $this->userSessionDAO->set(self::SESSION_KEY_ABUSES_COUNTER, $counter); return $counter; }
/** * Checks whether it is time to trigger an event identified by group and id. * * @param string $group Event group * @param string $id Event id * * @return boolean */ public function shouldTriggerEvent($group, $id) { $sessionKey = self::SESSION_KEY_EVENT_TIME . md5($group) . '_' . md5($id); if (!$this->userSessionDAO->contains($sessionKey)) { $this->userSessionDAO->set($sessionKey, time()); return true; } else { $diff = time() - $this->userSessionDAO->get($sessionKey); if ($diff > $this->getEventTimeThreshold($group)) { $this->userSessionDAO->set($sessionKey, time()); return true; } } return false; }
/** * Returns the original username if exists. * * @return string|null */ public function getOriginalUserName() { if ($this->userSessionDAO->contains(self::SESSION_KEY_ORIGINAL_USERNAME)) { return $this->userSessionDAO->get(self::SESSION_KEY_ORIGINAL_USERNAME); } else { return null; } }