public function authenticate() { $nick = strtolower($this->username); $user = Users::model()->find('LOWER(email)=?', array($nick)); if ($user === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif (!$user->validatePassword($this->password, $user->salt)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } elseif ($user->status == 0) { $this->errorCode = self::ERROR_PASSWORD_INVALID; return 2; } elseif ($user->status == 4) { // user is banned $this->errorCode = self::ERROR_PASSWORD_INVALID; return 3; } else { $this->_id = $user->id; $this->username = $user->email; $this->setState('isAdmin', $user->status == 3); $this->setState('permissions', $user->status); $this->setState('nick', $user->nick); $this->setState('session_key', md5($user->email . time() . uniqid() . $user->salt)); $this->setState('user_ip', Yii::app()->request->userHostAddress); Sessions::model()->deleteAllByAttributes(array('user_id' => $user->id)); $this->errorCode = self::ERROR_NONE; } return $this->errorCode == self::ERROR_NONE; }
/** * 检查用户是否已经登录 * @param unknown_type $username */ public function checkLoginState($username) { $string = 's:' . strlen($username) . ':"' . $username . '"'; $criteria = new CDbCriteria(); $criteria->addSearchCondition('data', $string); $model = Sessions::model()->find($criteria); return $model; }
public static function getOnlineUsers() { $sessions = Sessions::model()->findAll(); $temp = array(); foreach ($sessions as $session) { $temp[] = $session->user; } return $temp; }
public function afterDelete() { parent::afterDelete(); $shared = Shared::model()->findAllByAttributes(array('cam_id' => $this->id)); foreach ($shared as $s) { Notifications::model()->deleteAllByAttributes(array('shared_id' => $s->id, 'status' => 1)); $s->delete(); } Sessions::model()->deleteAllByAttributes(array('real_id' => $this->id)); Sessions::model()->deleteAllByAttributes(array('real_id' => $this->id . '_low')); return true; }
public function actionCheck($id = '', $clientAddr = '') { if (!$id && !$clientAddr && isset($_POST['data'])) { $data = json_decode($_POST['data'], 1); $id = $data['id']; $clientAddr = $data['clientAddr']; } $response = array('result' => 'fail', 'id' => ''); if (empty($id) && $this->validateRequest('id', $id)) { $response['id'] = 'empty or invalid id'; $this->renderJSON($response); } if (empty($clientAddr) && $this->validateRequest('ip', $clientAddr)) { $response['id'] = 'empty or invalid ip'; $this->renderJSON($response); } $session_id = Sessions::model()->findByAttributes(array('session_id' => $id), array('select' => 'real_id, ip')); if ($session_id) { $cam = Cams::model()->findByPK($session_id->real_id); if ($cam->is_public) { $response['result'] = 'success'; $response['id'] = $session_id->real_id; } elseif ($session_id->ip == $clientAddr) { $response['result'] = 'success'; $response['id'] = $session_id->real_id; } else { $response['id'] = 'huge fail'; } } else { $cam = Cams::model()->findByPK($id); if ($cam && $cam->is_public) { $response['result'] = 'success'; $response['id'] = $id; } else { $response['id'] = 'huge fail'; } } $this->renderJSON($response); }
/** * This function checks if the XML-RPC session key is valid. If yes returns true, otherwise false and sends an error message with error code 1 * * @access protected * @param string $sSessionKey Auth credentials * @return bool */ protected function _checkSessionKey($sSessionKey) { $criteria = new CDbCriteria(); $criteria->condition = 'expire < ' . time(); Sessions::model()->deleteAll($criteria); $oResult = Sessions::model()->findByPk($sSessionKey); if (is_null($oResult)) { return false; } else { $this->_jumpStartSession($oResult->data); return true; } }
/** * 检查登录状态 */ public function actionCheckLoginState() { $username = $_GET['username']; $string = 's:' . strlen($username) . ':"' . $username . '"'; $criteria = new CDbCriteria(); $criteria->addSearchCondition('data', $string); $model = Sessions::model()->find($criteria); if ($model) { $session = UtilSession::parseSession(Yii::app()->session->readSession($model->id)); $ip = $session['loginIp']; // $ip = '125.68.51.203'; $region = UtilNet::getIPLoc($ip); $result = array('id' => $model->id, 'msg' => "<b>检测到您的帐号当前已经在" . $region->province . '.' . $region->city . '.' . $region->district . "登录</b><br />是否要注销,重新登录"); echo json_encode($result); } else { $result = array('msg' => 'false'); echo json_encode($result); } }
/** * 当前在线人数 */ public function onlineStatistics() { return Sessions::model()->count(); }