public function authenticate() { $record = User::model()->find('user_name=:username and not_login=0', array(':username' => $this->username)); if ($record === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($record->password !== crypt($this->password, $record->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->_id = $record->id; foreach ($record as $k => $v) { $this->setState($k, $v); } //更新user_online表 if (!($userOnline = UserOnline::model()->findByPk($record->id))) { $userOnline = new UserOnline(); } $userOnline->setAttributes(array('id' => $record->id, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); $userOnline->save(); // SysLog::model()->createLog($record->id); $this->errorCode = self::ERROR_NONE; } } //var_dump($this->errorCode); return !$this->errorCode; }
public function updateCurrentUserStatus() { $userId = Yii::app()->user->id; if ($userId) { $model = $this->findByPk($userId); if (!$model) { $model = new UserOnline(); $model->setAttributes(array('id' => $userId, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); } else { $model = new UserOnline(); $model->setAttributes(array('id' => $userId, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); } $model->save(); } }
/** * 刷新在线时间 */ public function refreshOnline() { $model = new UserOnline(); $uid = Yii::app()->user->id; $condition = 'uid=' . $uid; $count = $model->count($condition); if ($count > 0) { $attribute = array('activeTime' => time()); $model = $model->find($condition); $model->attributes = $attribute; $model->save(); } else { $attribute = array('uid' => Yii::app()->user->id, 'username' => Yii::app()->user->name, 'activeTime' => time()); $model->attributes = $attribute; $model->save(); } }
/** * Logs out the current user and redirect to homepage. */ public function actionLogout() { $userOnline = UserOnline::model()->findByPk(Yii::app()->user->id); User::model()->updateByPk(Yii::app()->user->id, array("last_visit_time" => time())); if ($userOnline !== null) { $userOnline->delete(); } Yii::app()->user->logout(); $this->redirect(Yii::app()->homeUrl); }
/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $replaceOldFile = FALSE) { $allowed = new UserOnline(); $upload_allowed = $allowed->UserProperties(); if (!$upload_allowed) { return array('error' => "You are not allowed to upload files yet."); } if (!is_writable($uploadDirectory)) { return array('error' => "Server error. Upload directory isn't writable."); } if (!$this->file) { return array('error' => 'No files were uploaded.'); } $size = $this->file->getSize(); if ($size == 0) { return array('error' => 'File is empty'); } if ($size > $this->sizeLimit) { return array('error' => 'File is too large'); } $pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; $filename = uniqid(); $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.'); } if (!$replaceOldFile) { /// don't overwrite previous files that were uploaded while (file_exists($uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) { return array('success' => true, 'filename' => $filename . '.' . $ext); } else { return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered'); } }
public function insertDatabase($user) { $options = ['cost' => 12]; $this->password = password_hash($this->password, PASSWORD_BCRYPT, $options); $this->excuteInsert(User::TABLENAME, get_object_vars($this), $user); $useronline = new UserOnline(); $useronline->excuteInsert(UserOnline::TABLENAME, get_object_vars($useronline), $user); }
$renderer->assign('user', $User); $renderer->assign('active_pet', $Pet); } // end if cookies are set $renderer->assign('logged_in', $logged_in); // Handle the online status of this client. $online = new UserOnline($db); if ($logged_in == true) { $online = $online->findOneByUserId($User->getUserId()); } else { $online = $online->findOneByClientIp($_SERVER['REMOTE_ADDR']); } // end is a guest // If the user/guest was not found as online, recreate the instance and // we're all set. Otherwise, we have the appropriate instance loaded and // ready for updating. if ($online == null) { $online = new UserOnline($db); } // Add the correct stuff and save. if ($logged_in == true) { $online->setUserType('user'); $online->setUserId($User->getUserId()); } else { $online->setUserType('guest'); $online->setClientIp($_SERVER['REMOTE_ADDR']); } // end guest $online->setClientUserAgent($_SERVER['HTTP_USER_AGENT']); $online->setDatetimeLastActive($online->sysdate()); $online->save();
$message_count = ''; if (is_object($User) == true) { if ($User->hasPermission('admin_panel') == true) { $renderer->assign('show_admin_panel', true); } // Get the number of unread messages the user has. $count = new Message($db); $count = $count->findBy(array('recipient_user_id' => $User->getUserId(), 'message_read' => 'N'), null, true); if ($count > 0) { $message_count = " ({$count})"; } } // end user exists $renderer->assign('unread_message_count', $message_count); // Get the number of users online for showing somewheres in the layout. $online_users = UserOnline::totalUsers($db); $renderer->assign('online_users', $online_users); // Get the baords to list. $BOARDS = array(); // If the user is not logged in, don't bother pulling boards with permissions. $ARGS = array(array('table' => 'board_category', 'column' => 'required_permission_id', 'value' => 0)); if ($User != null) { $ARGS = array(); } $categories = new BoardCategory($db); $categories = $categories->findBy($ARGS, array('direction' => 'ASC', 'columns' => array(array('table' => 'board_category', 'column' => 'order_by')))); foreach ($categories as $category) { if ($User != null) { if ($category->hasAccess($User) == false) { continue; }
<?php /** * Check if the user is banned */ $banned = UserBan::IsBanned($_SERVER['REMOTE_ADDR']); /** * If the user is banned, stop the execution of the website * and output the banned signals over json */ if ($banned) { die(json_encode(array("msg" => $_['BANNED'], "response" => 0, "registered" => 0))); } /** * Start the UserOnline class */ $online = new UserOnline(); /** * Check if admin is online or not */ $admin_online = $online->AdminOnline(); /** * If the current guest has allready registered, we output 1, 0 otherwise */ $registered_user = isset($_SESSION['visitor_chat_user']) ? 1 : 0; /** * Pass the admin online return signals to json and to browser */ echo $admin_online >= 1 ? json_encode(array("msg" => $_['ADMIN_ONLINE'], "response" => 1, "registered" => $registered_user)) : json_encode(array("msg" => $_['ADMIN_OFFLINE'], "response" => 0, "registered" => $registered_user));
Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('PUT /v1/main/useronline/@id', function ($id) { try { $object = UserOnline::update($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('DELETE /v1/main/useronline/@id', function ($id) { try { $object = UserOnline::delete($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); //============================================================================= //Vehicle //============================================================================= Flight::route('GET /v1/main/vehicle', function () { $company = Flight::request()->query->company; try { if ($company) { $array = Vehicle::selectByCompany($company); } else { $array = Vehicle::selectAll();
* * @author Nicholas 'Owl' Evans <*****@*****.**> * @copyright Nicolas Evans, 2007 * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 * @package Kitto_Kitto_Kitto * @subpackage Core * @version 1.0.0 **/ // The maximum number of users to show on each page. $max_items_per_page = 30; // Handle the page ID for slicing and dicing the inventory up. $page_id = stripinput($_REQUEST['page']); if ($page_id == null || $page_id <= 0) { $page_id = 1; } $start = ($page_id - 1) * $max_items_per_page; $end = ($page_id - 1) * $max_items_per_page + $max_items_per_page; // Generate the pagination. $total = UserOnline::totalUnhiddenUsers($db); $pagination = pagination('online', $total, $max_items_per_page, $page_id); $users = UserOnline::findOnlineUsers($start, $end, $db); $USER_LIST = array(); foreach ($users as $user) { $USER_LIST[] = array('id' => $user->getUserId(), 'name' => $user->getUserName(), 'last_active' => $user->getDatetimeLastActive()); } // end users formatting loop $TOTAL = array('sum' => UserOnline::totalOnline($db), 'hidden' => UserOnline::totalHidden($db), 'guests' => UserOnline::totalGuests($db)); $renderer->assign('pagination', $pagination); $renderer->assign('users', $USER_LIST); $renderer->assign('totals', $TOTAL); $renderer->display('meta/online.tpl');