/** * Override so we can set a custom file cache path. * * @return null */ public function init() { if (!$this->cachePath) { $this->cachePath = craft()->path->getCachePath(); } parent::init(); }
public function actionActivated($_hash) { $cache = new CFileCache(); $cache->init(); $hash = $cache->get('registerActivated' . $_hash); $cache->delete('registerActivated' . $_hash); // Ключ не найден, возможно пытаются подобрать или истекло время отведенное для активации аккаунта if ($hash === FALSE) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Ключ для активации аккаунта не найден.')); $this->redirect(array('index')); } $user = Users::model()->findByPk($hash['user_id']); if (!$user) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Аккаунт не найден.')); } elseif ($user->isActivated()) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Аккаунт уже активирован.')); } else { // Создаю игровой аккаунт try { $l2 = l2('ls', $user->ls_id)->connect(); $l2->insertAccount($user->login, $hash['password']); $user->activated = Users::STATUS_ACTIVATED; $user->save(FALSE); user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Активация аккаунта прошла успешно. Приятной игры!')); notify()->registerStep2($hash['email'], array('login' => $user->login, 'password' => $hash['password'])); } catch (Exception $e) { user()->setFlash(FlashConst::MESSAGE_ERROR, $e->getMessage()); } } $this->redirect(array('index')); }
public function init() { // added support for path aliases if ($this->cachePath !== null) { $this->cachePath = Yii::getPathOfAlias($this->cachePath); } parent::init(); }
public function actionStep2($hash) { $cache = new CFileCache(); $cache->init(); if (($hashInfo = $cache->get($this->_cacheName . $hash)) !== FALSE) { $cache->delete($this->_cacheName . $hash); $user = db()->createCommand("SELECT COUNT(0) FROM `{{users}}` WHERE `email` = :email AND `login` = :login LIMIT 1")->bindParam('email', $hashInfo['email'], PDO::PARAM_STR)->bindParam('login', $hashInfo['login'], PDO::PARAM_STR)->queryScalar(); if ($user) { $newPassword = Users::generatePassword(rand(Users::PASSWORD_MIN_LENGTH, Users::PASSWORD_MAX_LENGTH)); // Обновляю пароль на сервере try { $l2 = l2('ls', $hashInfo['ls_id'])->connect(); $encryptPassword = $l2->passwordEncrypt($newPassword); $login = $hashInfo['login']; $email = $hashInfo['email']; $res = $l2->getDb()->createCommand("UPDATE {{accounts}} SET password = :password WHERE login = :login LIMIT 1")->bindParam('password', $encryptPassword, PDO::PARAM_STR)->bindParam('login', $login, PDO::PARAM_STR)->execute(); if ($res) { $encryptPassword = Users::hashPassword($newPassword); db()->createCommand("UPDATE {{users}} SET password = :password WHERE email = :email AND login = :login LIMIT 1")->bindParam('password', $encryptPassword, PDO::PARAM_STR)->bindParam('email', $email, PDO::PARAM_STR)->bindParam('login', $login, PDO::PARAM_STR)->execute(); notify()->forgottenPasswordStep2($email, array('password' => $newPassword)); user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'На почту указанную при регистрации отправлен новый пароль.')); } else { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); } } catch (Exception $e) { user()->setFlash(FlashConst::MESSAGE_ERROR, $e->getMessage()); } } else { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Аккаунт не найден.')); } } else { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Ключ для восстановления пароля не найден.')); } if (user()->hasFlash(FlashConst::MESSAGE_ERROR)) { $this->redirect(array('index')); } $this->redirect(array('/login/default/index')); }
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')); } }
/** * @return CFileCache */ private function getCache() { static $cache; if (!$cache) { $cache = new CFileCache(); $cache->init(); } return $cache; }
/** * */ public function init() { parent::init(); $this->setGCProbability(100); }
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; }
/** * Регистрация аккаунта */ 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; }
public function init() { $this->cachePath = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'apiCallCache'; parent::init(); }