/** * Destroy user session */ public function actionLogout() { try { // we might not be signed in actually $this->user = new User(); } catch (UserNotAuthenticatedException $e) { $this->flashSuccess = 'You are already logged out'; } // as we are logging out, leave us from all rooms if ($this->user != NULL) { $inRooms = $this->user->inRooms(); if (!empty($inRooms)) { $time = mktime(); foreach ($inRooms as $room) { // message about it $message = new MessageSpeak($room, $time); $message->leave($room, $time, $this->user->getShortName()); } // remove us from participants $room = new Room(); $room->removeParticipant($this->user->getId()); } $this->flashSuccess = 'You have been logged out'; $this->user->signOut(); } $this->bag->token = Fari_FormToken::create(); $this->renderAction('login'); }
function __construct($time = NULL) { if (!isset($time)) { $time = mktime(); } $this->db = Fari_Db::getConnection(); parent::__construct($this->db); $cutoff = $time - 60 * 10; // check if user has a timestamp older than 5 minutes in a room $leave = $this->db->select('room_users JOIN users ON room_users.user=users.id', 'user, room, short', "timestamp < {$cutoff}"); if (!empty($leave)) { $message = new MessageSpeak(); foreach ($leave as $user) { // leaving message $message->leave($user['room'], $time, $user['short']); } // clear them out from the room $this->db->delete('room_users', "timestamp < {$cutoff}"); } }
function kickGuests($roomId, $time) { $leaving = $this->db->select('user_permissions JOIN users ON user_permissions.user = users.id', 'id, short', array('role' => 'guest', 'room' => $roomId)); if (!empty($leaving)) { $message = new MessageSpeak(); foreach ($leaving as $kick) { // you should be leaving... $this->db->delete('user_permissions', array('user' => $kick['id'], 'room' => $roomId)); // you are leaving... $message->leave($roomId, $time, $kick['short']); // you are actually leaving... $this->db->delete('room_users', array('user' => $kick['id'], 'room' => $roomId)); } } }
/** * Leave the room */ public function actionLeave($roomId) { if (Fari_Filter::isInt($roomId)) { // are we actually in the room? if ($this->user->inRoom($roomId)) { // remove us from participants $this->user->leaveRoom($roomId); // message about it $time = mktime(); $message = new MessageSpeak($roomId, $time); $message->leave($roomId, $time, $this->user->getShortName()); // the user might be a guest in which case show her a slightly different exit message if ($this->user->isGuest()) { $this->renderAction('bye'); } } } // redir either way $this->redirectTo('/'); }
private function leaveRoom($userId) { $result = $this->db->selectRow('room_users JOIN users on room_users.user = users.id', 'room, short', array('user' => $userId)); if (!empty($result)) { $time = mktime(); $message = new MessageSpeak($result['room'], $time); $message->leave($result['room'], $time, $result['short']); // delete in one big swoop $this->db->delete('room_users', array('user' => $userId)); } }