public function authenticate()
 {
     $record = User::model()->with('group')->findByAttributes(array('login' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->banned === '1') {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($record->password !== User::encodePassword($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_id = $record->id;
                 $this->_login = $record->login;
                 $record->last_login = date('Y-m-d H:i:s');
                 $record->login_ip = CMS::getip();
                 $record->save(false, false, false);
                 $this->setState('id', $record->id);
                 $this->setState('username', $record->login);
                 $this->setState('roles', $record->group->alias);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return !$this->errorCode;
 }
示例#2
0
 public function init()
 {
     $this->userIP = CMS::getip();
     if ($this->verify_ip_ban()) {
         header("HTTP/1.0 403 Forbidden");
         header("HTTP/1.1 403 Forbidden");
         header("Status: 403 Forbidden");
         Yii::app()->controllerMap['bannedip'] = 'application.components.bannedIP.bannedIPController';
         Yii::app()->catchAllRequest = array('bannedip/index');
     }
 }
示例#3
0
 public function set($message, $params = array())
 {
     $browser = new Browser();
     $model = new Timeline();
     $model->user_id = Yii::app()->user->id;
     $model->message = Yii::t('timeline', $message, $params);
     $model->user_agent = $browser->getUserAgent();
     $model->ip = CMS::getip();
     $model->user_platform = $browser->getPlatform();
     $model->save(false, false, false);
 }
示例#4
0
 public function init()
 {
     $config = Yii::app()->settings->get('core');
     if ($config['site_close']) {
         $users = explode(',', $config['site_close_allowed_users']);
         $ips = explode(',', $config['site_close_allowed_ip']);
         $disable = in_array(Yii::app()->user->name, $users);
         foreach ($this->roles as $role) {
             $disable = $disable || Yii::app()->user->checkAccess($role);
         }
         $disable = $disable || in_array(Yii::app()->request->getPathInfo(), $this->urls);
         $disable = $disable || in_array(CMS::getip(), $ips);
         //check "allowed IP"
         if (!$disable) {
             if ($this->capUrl === 'maintenance/index') {
                 Yii::app()->controllerMap['maintenance'] = 'application.components.MaintenanceMode.MaintenanceController';
             }
             Yii::app()->catchAllRequest = array($this->capUrl);
         }
     }
 }
示例#5
0
 public function actionRating()
 {
     $request = Yii::app()->request;
     if ($request->isAjaxRequest) {
         $mod = $_REQUEST['module'];
         $rating = (int) $_REQUEST['rating'];
         $id = (int) $_REQUEST['pid'];
         $baseModel = $_REQUEST['model'];
         $model = $baseModel::model()->findByPk($id);
         if ($model && in_array($rating, array(1, 2, 3, 4, 5))) {
             $model->score += 1;
             $model->rating += $rating;
             $model->save();
             $new = time();
             $ratingModel = new EngineRating();
             $ratingModel->mid = $id;
             $ratingModel->modul = $mod;
             $ratingModel->time = $new;
             $ratingModel->user_id = Yii::app()->user->getId();
             $ratingModel->host = CMS::getip();
             $ratingModel->save();
             $cookie = new CHttpCookie($mod . "-" . $id, $id);
             $cookie->expire = time() + 60 * 60 * 24 * 60;
             Yii::app()->request->cookies[$mod . "-" . $id] = $cookie;
             $this->widget('ext.rating.Rating', array('pid' => $id, 'rating' => $model->rating, 'votes' => $model->score, 'active' => false));
         }
     } else {
         die('error');
     }
 }
示例#6
0
 /**
  * Initialize stats component
  */
 public function __construct()
 {
     if (!Yii::app()->request->isAjaxRequest && $this->checkIgnoreRoute()) {
         $offset = 0;
         $t = time() + 3600 * $offset;
         $day = date("D", $t);
         $dt = date("Ymd", $t);
         $tm = date("H:i", $t);
         $refer = $_SERVER['HTTP_REFERER'];
         $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
         $user = $_SERVER['HTTP_USER_AGENT'];
         $req = $_SERVER['REQUEST_URI'];
         if ($ip = $_SERVER['HTTP_X_FORWARDED_FOR']) {
             if (!stristr($_SERVER['HTTP_X_FORWARDED_FOR'], CMS::getip()) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $ip .= ", " . CMS::getip();
             } else {
                 $ip = CMS::getip();
             }
             $proxy = CMS::getip();
         } else {
             $ip = CMS::getip();
             $proxy = "";
         }
         if ($proxy == $ip) {
             $proxy = "";
         }
         $a = explode(", ", $ip);
         $real_ip = $a[count($a) - 1];
         if (!empty($proxy)) {
             $host = gethostbyaddr($proxy);
         } else {
             if ($host = gethostbyaddr($ip)) {
             } else {
                 if ($host = gethostbyaddr($real_ip)) {
                 } else {
                     $host = $ip;
                 }
             }
         }
         $model = new StatsSurf();
         $model->day = $day;
         $model->dt = $dt;
         $model->tm = $tm;
         $model->refer = $refer;
         $model->ip = $ip;
         $model->proxy = $proxy;
         $model->host = $host;
         $model->lang = $lang;
         $model->user = $user;
         $model->req = $req;
         if (!$model->save(false, false, false)) {
             Yii::log('Error save stats', 'info', 'stats');
         }
     }
 }