Ejemplo n.º 1
0
 /**
  * expires у нас теперь фиксированный для всех файлов
  * @param $id
  * @param $value
  * @param int $expire
  * @param null $dependency
  * @return mixed
  */
 public function set($id, $value, $expire = 0, $dependency = null)
 {
     if ($this->embedExpiry) {
         return parent::set($id, $value, $expire, $dependency);
     } else {
         return parent::set($id, $value, $this->fixedExpiry, $dependency);
     }
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     if (!user()->isGuest) {
         // Если авторизирован
         $this->redirect(array('/cabinet/default/index'));
     }
     $model = new ForgottenPasswordForm();
     if (isset($_POST['ForgottenPasswordForm'])) {
         $model->attributes = $_POST['ForgottenPasswordForm'];
         if ($model->validate()) {
             $cache = new CFileCache();
             $cache->init();
             $cacheData = array('hash' => md5(randomString(rand(10, 30)) . userIp() . time()), 'login' => $model->login, 'ls_id' => $model->gs_list[$model->gs_id]['login_id'], 'email' => $model->email);
             $cache->set($this->_cacheName . $cacheData['hash'], $cacheData, (int) config('forgotten_password.cache_time') * 60);
             notify()->forgottenPasswordStep1($model->email, array('hash' => $cacheData['hash']));
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'На Email <b>:email</b> отправлены инструкции по восстановлению пароля.', array(':email' => $model->email)));
             $this->refresh();
         }
     }
     $this->render('//forgotten-password', array('model' => $model));
 }
Ejemplo n.º 3
0
 public function actionTeleport($char_id)
 {
     $statusOn = ActiveRecord::STATUS_ON;
     $gsId = user()->getGsId();
     $cache = new CFileCache();
     $cache->init();
     $dependency = new CDbCacheDependency("SELECT MAX(UNIX_TIMESTAMP(updated_at)) FROM {{gs}} WHERE id = :id AND status = :status LIMIT 1");
     $dependency->params = array('id' => $gsId, 'status' => $statusOn);
     $gsInfo = db()->cache(3600 * 24, $dependency)->createCommand("SELECT * FROM {{gs}} WHERE id = :id AND status = :status LIMIT 1")->bindParam('status', $statusOn, PDO::PARAM_INT)->bindParam('id', $gsId, PDO::PARAM_INT)->queryRow();
     if ($gsInfo === FALSE || !$gsInfo['allow_teleport']) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Телепортация отключена.'));
         $this->redirect(array('index'));
     }
     $userId = user()->getId();
     $cacheName = strtr(CacheNames::CHARACTER_TELEPORT, array(':user_id' => $userId, ':char_id' => $char_id, ':gs_id' => $gsId));
     $teleportsInfo = $cache->get($cacheName);
     if ($teleportsInfo !== FALSE) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Вы уже недавно были телепортированы в :city.', array(':city' => '<b>' . $teleportsInfo['city'] . '</b>')));
         $this->redirect(array('index'));
     }
     try {
         $l2 = l2('gs', $gsId)->connect();
         $charIdFieldName = $l2->getField('characters.char_id');
         $command = $l2->getDb()->createCommand();
         $command->where($charIdFieldName . ' = :char_id AND account_name = :account_name', array(':char_id' => $char_id, ':account_name' => user()->get('login')));
         $character = $l2->characters($command)->queryRow();
         if ($character === FALSE) {
             user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Персонаж не найден.'));
             $this->redirect(array('index'));
         }
         // Если в игре
         if ($character['online'] != 0) {
             user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Персонаж в игре.'));
             $this->redirect(array('index'));
         }
         $city = Lineage::getRandomCity();
         $userName = user()->get('login');
         $x = $city['coordinates'][0]['x'];
         $y = $city['coordinates'][0]['y'];
         $z = $city['coordinates'][0]['z'];
         // Телепорт игрока
         $res = $l2->getDb()->createCommand("UPDATE {{characters}} SET x = :x, y = :y, z = :z WHERE " . $charIdFieldName . " = :char_id AND account_name = :account_name LIMIT 1")->bindParam('x', $x, PDO::PARAM_STR)->bindParam('y', $y, PDO::PARAM_STR)->bindParam('z', $z, PDO::PARAM_STR)->bindParam('char_id', $char_id, PDO::PARAM_INT)->bindParam('account_name', $userName, PDO::PARAM_STR)->execute();
         if ($res) {
             $cache->set($cacheName, array('char_id' => $char_id, 'city' => $city['name']), $gsInfo['teleport_time'] * 60);
             // Логирую действие юзера
             if (app()->params['user_actions_log']) {
                 $log = new UserActionsLog();
                 $log->user_id = user()->getId();
                 $log->action_id = UserActionsLog::ACTION_TELEPORT_TO_TOWN;
                 $log->params = json_encode($city);
                 $log->save(FALSE);
             }
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Персонаж был телепортрован в :city.', array(':city' => '<b>' . $city['name'] . '</b>')));
             $this->redirect(array('index'));
         } else {
             user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.'));
             $this->redirect(array('index'));
         }
     } catch (Exception $e) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.'));
         Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__ . ' ' . __LINE__);
         $this->redirect(array('index'));
     }
 }
Ejemplo n.º 4
0
 public function getSmsNumbers()
 {
     $projectId = 1;
     $cacheName = 'WTPSMSLIST' . $projectId;
     $cache = new CFileCache();
     $cache->init();
     if (!($data = $cache->get($cacheName))) {
         $res = json_decode(file_get_contents('http://waytopay.org/api/getsmsjson/' . $this->smsProjectId), TRUE);
         $itemCost = app()->controller->gs->deposit_course_payments;
         $data = array();
         foreach ($res as $countryCode => $row) {
             $operators = array();
             foreach ($row as $item) {
                 $countItems = floor($item['profit'] / $itemCost);
                 if ($countItems < 1) {
                     continue;
                 }
                 $item['count_items'] = $countItems;
                 $operators[$item['operator_id']][$countItems] = $item;
             }
             if (!$operators) {
                 continue;
             }
             $data[$countryCode] = $operators;
         }
         // Sort
         foreach ($data as $k => &$v) {
             foreach ($v as $oId => &$v2) {
                 ksort($v2);
             }
         }
         $cache->set($cacheName, $data, 300);
     }
     return $data;
 }
Ejemplo n.º 5
0
 /**
  * Регистрация аккаунта
  */
 public function registerAccount()
 {
     $login = $this->getLogin();
     // Регистрация через почту
     if (config('register.confirm_email')) {
         $activatedHash = Users::generateActivatedHash();
         $user = $this->_createAccount();
         notify()->registerStep1($this->email, array('hash' => $activatedHash));
         $cache = new CFileCache();
         $cache->init();
         $cache->set('registerActivated' . $activatedHash, array('user_id' => $user->getPrimaryKey(), 'password' => $this->password, 'email' => $this->email), (int) config('register.confirm_email.time') * 60);
         user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Вы успешно зарегистрировали аккаунт. На почту :email отправлены инструкции по активации аккаута.', array(':email' => '<b>' . $this->email . '</b>')));
     } else {
         $ls_transaction = $this->l2->getDb()->beginTransaction();
         try {
             // Создаю аккаунт на сервере
             $this->l2->insertAccount($login, $this->password);
             $user = $this->_createAccount();
             notify()->registerNoEmailActivated($this->email, array('server_name' => $this->gs_list[$this->gs_id]['name'], 'login' => $login, 'password' => $this->password, 'referer' => $user->referer));
             $ls_transaction->commit();
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Вы успешно зарегистрировали аккаунт. Приятной игры.'));
             //$this->downloadFileInfoAfterRegister();
         } catch (Exception $e) {
             $ls_transaction->rollback();
             user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.'));
             Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __FILE__ . '::' . __LINE__);
         }
     }
     return TRUE;
 }
Ejemplo n.º 6
0
 /**
  * Stores a value identified by a key into cache. If the cache already contains such a key, the existing value and
  * expiration time will be replaced with the new ones.
  *
  * @param string             $id         The key identifying the value to be cached
  * @param mixed              $value      The value to be cached
  * @param int                $expire     The number of seconds in which the cached value will expire. 0 means never
  *                                       expire.
  * @param \ICacheDependency $dependency Dependency of the cached item. If the dependency changes, the item is
  *                                       labeled invalid.
  *
  * @return bool true if the value is successfully stored into cache, false otherwise.
  */
 public function set($id, $value, $expire = null, $dependency = null)
 {
     $this->_originalKey = $id;
     return parent::set($id, $value, $expire, $dependency);
 }