set() public method

A basic setter, which will set a value to a given property in the $_SESSION array, stored in the key of $this->_index
public set ( string $name, string $value )
$name string The name of the property
$value string The value of the property
Ejemplo n.º 1
0
 public function testSetData()
 {
     $this->cookie->set('fairy', 'test');
     $this->cookie->set_cookie_data(array('fairy' => 'Blum'));
     $this->assertEquals(0, count($this->cookie->get_updates()));
     $this->assertEquals('Blum', $this->cookie->get('fairy', 'test'));
 }
 private function __createCookie($username, $password)
 {
     if ($this->_Parent->Configuration->get('use-sessions', 'frontend-authentication') == 'yes') {
         $_SESSION[__SYM_COOKIE_PREFIX_ . 'front-end-authentication'] = array('username' => $username, 'password' => md5($password));
     } else {
         $Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'front-end-authentication', 24 * 60 * 60, __SYM_COOKIE_PATH__);
         $Cookie->set('username', $username);
         $Cookie->set('password', md5($password));
     }
 }
 protected function __trigger()
 {
     $supported_language_codes = LanguageRedirect::instance()->getSupportedLanguageCodes();
     // only do something when there is a set of supported languages defined
     if (!empty($supported_language_codes)) {
         $current_language_code = LanguageRedirect::instance()->getLanguageCode();
         // no redirect, set current language and region in cookie
         if (isset($current_language_code) and in_array($current_language_code, $supported_language_codes)) {
             $Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
             $Cookie->set('language', LanguageRedirect::instance()->getLanguage());
             $Cookie->set('region', LanguageRedirect::instance()->getRegion());
         } else {
             $current_path = !isset($current_language_code) ? $this->_env['param']['current-path'] : substr($this->_env['param']['current-path'], strlen($current_language_code) + 1);
             $browser_languages = $this->getBrowserLanguages();
             foreach ($browser_languages as $language) {
                 if (in_array($language, $supported_language_codes)) {
                     $in_browser_languages = true;
                     $browser_language = $language;
                     break;
                 }
             }
             $Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
             $cookie_language_code = $Cookie->get('language');
             if (strlen($cookie_language_code) > 0) {
                 $language_code = $Cookie->get('region') ? $cookie_language_code . '-' . $Cookie->get('region') : $cookie_language_code;
             } elseif ($in_browser_languages) {
                 $language_code = $browser_language;
             } else {
                 $language_code = $supported_language_codes[0];
             }
             // redirect and exit
             header('Location: ' . $this->_env['param']['root'] . '/' . $language_code . '/' . $current_path);
             die;
         }
         $all_languages = LanguageRedirect::instance()->getAllLanguages();
         $result = new XMLElement('language-redirect');
         $current_language_xml = new XMLElement('current-language', $all_languages[$current_language_code] ? $all_languages[$current_language_code] : $current_language_code);
         $current_language_xml->setAttribute('handle', $current_language_code);
         $result->appendChild($current_language_xml);
         $supported_languages_xml = new XMLElement('supported-languages');
         foreach ($supported_language_codes as $language) {
             $language_code = new XMLElement('item', $all_languages[$language] ? $all_languages[$language] : $language);
             $language_code->setAttribute('handle', $language);
             $supported_languages_xml->appendChild($language_code);
         }
         $result->appendChild($supported_languages_xml);
         return $result;
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * @runInSeparateProcess
  */
 public function testExtend()
 {
     $cookie = new Cookie();
     $cookie->set('testSet');
     $result = $cookie->extend('testExtend');
     $this->assertTrue($result);
     $this->assertEquals(serialize(array('testSet', 'testExtend')), $_COOKIE['openimporter_cookie']);
     $cookie->set('testSet', 'another_name');
     $result = $cookie->extend('testExtend', 'another_name');
     $this->assertTrue($result);
     $this->assertEquals(serialize(array('testSet', 'testExtend')), $_COOKIE['another_name']);
     $cookie->set('testSet');
     $result = $cookie->extend(null);
     $this->assertFalse($result);
 }
Ejemplo n.º 5
0
 public function index()
 {
     $map['id'] = array('neq', 1);
     $model = D('Shop_user');
     $count = $model->where($map)->count();
     if ($count > 0) {
         import("@.ORG.Util.Page");
         //创建分页对象
         if (!empty($_REQUEST['listRows'])) {
             $listRows = $_REQUEST['listRows'];
         } else {
             $listRows = '';
         }
         $p = new Page($count, $listRows);
         //分页查询数据
         $voList = $model->where($map)->order('id desc')->limit($p->firstRow . ',' . $p->listRows)->select();
         //获取文章分类名称
         //分页跳转的时候保证查询条件
         foreach ($map as $key => $val) {
             if (!is_array($val)) {
                 $p->parameter .= "{$key}=" . urlencode($val) . "&";
             }
         }
         //分页显示
         $page = $p->show();
         //模板赋值显示
         $this->assign('list', $voList);
         $this->assign("page", $page);
     }
     $this->assign('totalCount', $count);
     $this->assign('numPerPage', $p->listRows);
     $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
     Cookie::set('_currentUrl_', __SELF__);
     $this->display();
 }
 public function index()
 {
     $map = $this->_search();
     if (method_exists($this, '_filter')) {
         $this->_filter($map);
     }
     $map['type'] = 2;
     $model = D('Basic_download');
     $count = $model->where($map)->count();
     if ($count > 0) {
         import("@.ORG.Util.Page");
         if (!empty($_REQUEST['listRows'])) {
             $listRows = $_REQUEST['listRows'];
         } else {
             $listRows = '';
         }
         $p = new Page($count, $listRows);
         $voList = $model->where($map)->order('id desc')->limit($p->firstRow . ',' . $p->listRows)->select();
         foreach ($map as $key => $val) {
             if (!is_array($val)) {
                 $p->parameter .= "{$key}=" . urlencode($val) . "&";
             }
         }
         $page = $p->show();
         $this->assign('list', $voList);
         $this->assign("page", $page);
     }
     $this->assign('totalCount', $count);
     $this->assign('numPerPage', $p->listRows);
     $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
     Cookie::set('_currentUrl_', __SELF__);
     $this->display();
 }
Ejemplo n.º 7
0
 /**
  * デバイス変更
  */
 public function device_change()
 {
     $request = Request::getInstance();
     // デバイスの設定
     $device_type = 0;
     $device = $request->get('device');
     switch ($device) {
         case 'pc':
             $device_type = Config::get('DEVICE_PC');
             break;
         case 'm':
         case 'mb':
             $device_type = Config::get('DEVICE_MB');
             break;
         case 'sp':
             $device_type = Config::get('DEVICE_SP');
             break;
         case 'tb':
             $device_type = Config::get('DEVICE_TB');
             break;
         default:
             Cookie::set('device', null);
             $this->redirectBack(array('controller' => 'entries', 'action' => 'index'));
     }
     Cookie::set('device', $device_type);
     $this->redirectBack(array('controller' => 'entries', 'action' => 'index'));
 }
Ejemplo n.º 8
0
 public function edit()
 {
     $cate_tree = M("Ask")->findAll();
     $this->assign("cate_tree", $cate_tree);
     Cookie::set('_currentUrl_', NULL);
     parent::edit();
 }
 public function ajaxAddProblemAction()
 {
     $contestId = (int) Request::getPOST('contest-id');
     $remote = (int) Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     if (!array_key_exists($remote, StatusVars::$REMOTE_SCHOOL) || empty($problemCode) || empty($contestId)) {
         $this->renderError('缺少参数!');
     }
     // 默认题库
     Cookie::set('default_remote', $remote);
     $contestInfo = OjContestInterface::getDetail(array('id' => $contestId));
     if (empty($contestInfo)) {
         $this->renderError('竞赛不存在!');
     }
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     // 只能添加公开的题目,或者自建私有的题目
     if ($problemInfo['hidden'] && $problemInfo['user_id'] != $this->loginUserInfo['id']) {
         $this->renderError('权限不足,无法添加该题目!');
     }
     $globalIds = $contestInfo['global_ids'];
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经添加!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::CONTEST_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjContestInterface::addProblem(array('id' => $contestId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '添加成功!');
     $this->renderAjax(0);
 }
Ejemplo n.º 10
0
 function _initialize()
 {
     //先检查cookie
     if (!Cookie::is_set($_SESSION['cookietime'])) {
         redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
     } else {
         //保存cookie信息
         Cookie::set($_SESSION['cookietime'], '1', 60 * 60 * 3);
     }
     // 用户权限检查
     if (C('USER_AUTH_ON') && !in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))) {
         import('@.ORG.RBAC');
         if (!RBAC::AccessDecision()) {
             //检查认证识别号
             if (!$_SESSION[C('USER_AUTH_KEY')]) {
                 //跳转到认证网关
                 redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
             }
             // 没有权限 抛出错误
             if (C('RBAC_ERROR_PAGE')) {
                 // 定义权限错误页面
                 redirect(C('RBAC_ERROR_PAGE'));
             } else {
                 if (C('GUEST_AUTH_ON')) {
                     $this->assign('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY'));
                 }
                 // 提示错误信息
                 $this->error(L('_VALID_ACCESS_'));
             }
         }
     }
 }
Ejemplo n.º 11
0
 public function before()
 {
     parent::before();
     //Visits
     $visited = \Cookie::get('visited', false);
     if (!$visited) {
         \Dashboard::log_visitor();
         \Cookie::set("visited", true, time() + 86400);
     }
     // Cart
     \Config::load('cart', true);
     $cartManager = new \Cart\Manager(\Config::get('cart'));
     \CartManager::init($cartManager);
     \CartManager::context('Cart');
     // Set Visitors group default
     \Product\Model_Attribute::set_user_group(3);
     \Theme::instance()->active('frontend');
     \Theme::instance()->set_template($this->template);
     // Set a global variable so views can use it
     $seo = array('meta_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'canonical_links' => '', 'meta_robots_index' => 1, 'meta_robots_follow' => 1);
     \View::set_global('seo', $seo, false);
     \View::set_global('theme', \Theme::instance(), false);
     \View::set_global('logged', $this->check_logged(), false);
     \View::set_global('guest', $this->check_guest(), false);
     \View::set_global('logged_type', $this->check_logged_type(), false);
 }
Ejemplo n.º 12
0
 public function _login($user, $password, $remember)
 {
     if (!is_object($user)) {
         $username = $user;
         // Load the user
         $user = Sprig::factory('user', array('login' => $username))->load();
     }
     if (is_string($password)) {
         // Создаем хэш пароя
         $password = $this->hash($password);
     }
     // Проверяем наличие роли Login и соответствие пароля
     if ($user->has_role('login') and $user->password === $password) {
         // Если выбран чекбокс Запомнить меня
         if ($remember === TRUE) {
             // Token data
             $data = array('user_id' => $user->id, 'expires' => time() + $this->_config['lifetime'], 'user_agent' => sha1(Request::$user_agent));
             // Create a new autologin token
             $token = Sprig::factory('token')->values($data)->create();
             // Set the autologin cookie
             Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
         }
         // Finish the login
         $this->complete_login($user);
         return TRUE;
     }
     // Login failed
     return FALSE;
 }
Ejemplo n.º 13
0
 /**
  *	@fn login
  *	@short Action method to perform a login.
  */
 function login()
 {
     if ($this->request->is_post()) {
         $conn = Db::get_connection();
         $user_factory = new User();
         $users = $user_factory->find_all(array('where_clause' => "`username` = '{$conn->escape($_POST['username'])}' AND `password` = '" . md5($_POST['password']) . "'", 'limit' => 1));
         if (count($users) > 0) {
             $user = $users[0];
             $expires = $_POST['leave_me_registered'] ? Time::next_year() : Time::tomorrow();
             Cookie::set('_u', $user->username, $expires, "/", FALSE);
             Cookie::set('_uid', md5(Login::magic_phrase . $user->password), $expires, "/", FALSE);
             // Annotates the login in the database
             $user_login = new UserLogin();
             $user_login->user_id = $user->id;
             $user_login->performed_at = date("Y-m-d H:i:s");
             $user_login->save();
             $this->flash(sprintf(l('Welcome, %s'), $user->first), 'info');
             // When login is required to access a particular action, we may store controller & action in a session,
             // perform login, then redirect to the action requested in the first place
             if (isset($_SESSION['redirect_to'])) {
                 $this->redirect_to(array('controller' => $_SESSION['redirect_to']['controller'], 'action' => $_SESSION['redirect_to']['action']));
             } else {
                 $this->redirect_to(array('controller' => 'home'));
             }
             Db::close_connection($conn);
         } else {
             $this->flash(l('Bad username / password'), 'error');
         }
     }
     $this->redirect_to(array('action' => 'index'));
 }
Ejemplo n.º 14
0
 protected function _list($model, $map, $sortBy = '', $asc = false)
 {
     //取得满足条件的记录数
     $count = $model->table(array('tb_press_numinfo' => 'press_numinfo'))->join('tb_magazine  magazine on magazine.postCode = press_numinfo.postCode')->join('tb_magazine_terrm magazine_terrm on magazine_terrm.id = press_numinfo.termID')->join('tb_employee_newspaper employee_newspaper on magazine.postcode = employee_newspaper.postcode')->where($map)->count('press_numinfo.id');
     if ($count > 0) {
         import("ORG.Util.Page");
         //创建分页对象
         if (!empty($_REQUEST['listRows'])) {
             $listRows = $_REQUEST['listRows'];
         } else {
             $listRows = '';
         }
         $p = new Page($count, $listRows);
         //分页查询数据
         $fieldStr = 'press_numinfo.id as id, magazine.name as magazineName, magazine_terrm.name as magazineTerrmName, magazine_terrm.month as month, magazine_terrm.year as year, press_numinfo.printNum as printNum';
         $orderStr = 'magazine_terrm.year asc, magazine_terrm.month asc, magazine_terrm.id asc';
         $voList = $model->table(array('tb_press_numinfo' => 'press_numinfo'))->join('tb_magazine  magazine on magazine.postCode = press_numinfo.postCode')->join('tb_magazine_terrm magazine_terrm on magazine_terrm.id = press_numinfo.termID')->join('tb_employee_newspaper employee_newspaper on magazine.postcode = employee_newspaper.postcode')->where($map)->order($orderStr)->limit($p->firstRow . ',' . $p->listRows)->field($fieldStr)->select();
         //分页显示
         $page = $p->show();
         //模板赋值显示
         $this->assign('list', $voList);
         $this->assign("page", $page);
     }
     $this->assign('totalCount', $count);
     $this->assign('numPerPage', C('PAGE_LISTROWS'));
     $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
     Cookie::set('_currentUrl_', __SELF__);
     return;
 }
Ejemplo n.º 15
0
 public function checklogin()
 {
     $userEmail = isset($_POST["email"]) ? $_POST["email"] : Cookie::get("email");
     $userPassword = isset($_POST["password"]) ? md5($_POST["password"]) : Cookie::get("password");
     //验证用户信息
     $userDao = D('User');
     $user = $userDao->find("email='{$userEmail}' and password='******'", 'id,name,email,sex');
     //验证成功
     if ($user) {
         //更新登录时间
         $userDao->setField('lastLoginTime', time(), "id=" . $user->id);
         //D('Login')->add("userId='$user->id'");
         //记录登陆状态
         Session::set('mid', $user->id);
         Session::set('userInfo', $user);
         Cookie::set('email', $userEmail, 36000000);
         //记住登录
         if ($_POST["autologin"] == 'on') {
             Cookie::set("password", $userPassword, 36000000);
         }
         unset($userEmail, $userPassword);
         //跳转到Home页
         $this->redirect('index', 'Home');
         //验证失败
     } else {
         //跳转到登陆页面
         $this->redirect("login");
     }
 }
Ejemplo n.º 16
0
 public function action_index()
 {
     $abc = "f";
     //$user = ORM::factory('user', 1);
     //$this->response->body('欢迎:'.$user->name);
     $user = ORM::factory('user', $this->request->param('id', 1));
     $view = View::factory('welcome');
     $view->bind('user', $user);
     //echo Debug::vars($user);
     //echo Debug::source(__FILE__, __LINE__);
     //echo Debug::path(APPPATH);
     //
     //
     Cookie::set('key_name', '1625');
     Session::instance()->set('username', 'ffffffffffffffffffffffff');
     //设置Cooki1
     //Cookie::set('user_id', $user_id);
     //设置 Session
     //Session::instance()->set('key_name', 'value');
     //Session::instance()->set('user_id', $user_id);
     //取cookie session
     //echo Cookie::get('key_name');
     echo Session::instance()->get('username');
     $this->response->body($view->render());
 }
Ejemplo n.º 17
0
 /**
  * 注册
  * @method POST_indexAction
  * @param  string      $name [description]
  * @return [type]            [description]
  * @author NewFuture
  */
 public function POST_indexAction()
 {
     if (!($regInfo = Session::get('reg'))) {
         $this->response(0, '注册信息失效');
     } else {
         /*检查密码*/
         if (Input::post('password', $password, 'isMD5')) {
             $msg = '成功设置了新的密码作为云印密码!';
         } else {
             $msg = '使用刚才的验证密码作为运用登陆密码!';
             $password = $regInfo['password'];
         }
         /*开始注册*/
         $regInfo['password'] = Encrypt::encryptPwd($password, $regInfo['number']);
         if ($id = UserModel::insert($regInfo)) {
             /*注册成功*/
             $msg .= '(如果下次忘记密码后可以通过 手机,邮箱或者再次认证找回密码)';
             $regInfo['id'] = $id;
             $token = Auth::token($regInfo);
             Cookie::set('token', $token);
             unset($regInfo['password']);
             Session::del('reg');
             Session::set('user', $regInfo);
             $this->response(1, ['user' => $regInfo, 'token' => $token, 'msg' => $msg]);
         } else {
             $this->response(0, '注册失败');
         }
     }
 }
Ejemplo n.º 18
0
 /**
  *	@fn set
  *	@short Action method to set the user's home language.
  */
 public function set()
 {
     $lang = isset($_REQUEST['id']) ? $_REQUEST['id'] : 'en';
     Cookie::set('hl', $lang, Time::next_year(), '/');
     $this->redirect_to_referrer();
     $this->redirect_to(array('controller' => 'home'));
 }
Ejemplo n.º 19
0
 public function action_index()
 {
     Assets::package('jquery-ui');
     $cur_ds_id = (int) Arr::get($this->request->query(), 'ds_id', Cookie::get('ds_id'));
     $tree = Datasource_Data_Manager::get_tree();
     $cur_ds_id = Datasource_Data_Manager::exists($cur_ds_id) ? $cur_ds_id : Datasource_Data_Manager::$first_section;
     $ds = $this->section($cur_ds_id);
     $this->template->content = View::factory('datasource/content', array('content' => View::factory('datasource/data/index'), 'menu' => View::factory('datasource/data/menu', array('tree' => $tree, 'folders' => Datasource_Folder::get_all()))));
     $this->template->footer = NULL;
     $this->template->breadcrumbs = NULL;
     if ($ds instanceof Datasource_Section) {
         $this->set_title($ds->name);
         $limit = (int) Arr::get($this->request->query(), 'limit', Cookie::get('limit'));
         Cookie::set('ds_id', $cur_ds_id);
         $keyword = $this->request->query('keyword');
         if (!empty($limit)) {
             Cookie::set('limit', $limit);
             $this->section()->headline()->limit($limit);
         }
         $this->template->content->content->headline = $this->section()->headline()->render();
         $this->template->content->content->toolbar = View::factory('datasource/' . $ds->type() . '/toolbar', array('keyword' => $keyword));
         $this->template->set_global(array('datasource' => $ds));
         $this->template_js_params['DS_ID'] = $this->_section->id();
         $this->template_js_params['DS_TYPE'] = $this->_section->type();
     } else {
         $this->template->content->content = NULL;
     }
 }
Ejemplo n.º 20
0
 public function action_authorize()
 {
     if ($this->token and $this->token->token !== Arr::get($_GET, 'oauth_token')) {
         // Delete the token, it is not valid
         Cookie::delete($this->cookie);
         // Send the user back to the beginning
         Request::instance()->redirect($this->request->uri(array('action' => 'index')));
     }
     // Get the verifier
     $verifier = Arr::get($_GET, 'oauth_verifier');
     // Store the verifier in the token
     $this->token->verifier($verifier);
     // Exchange the request token for an access token
     $this->token = $this->provider->access_token($this->consumer, $this->token);
     // Store the access token
     Cookie::set($this->cookie, serialize($this->token));
     // At this point, we need to retrieve a unique twitter id for the user.
     $response = OAuth_Request::factory('resource', 'GET', 'http://api.twitter.com/1/account/verify_credentials.json')->param('oauth_consumer_key', Kohana::config('oauth.twitter.key'))->param('oauth_token', $this->token)->sign(OAuth_Signature::factory('HMAC-SHA1'), $this->consumer, $this->token)->execute();
     $response = json_decode($response);
     $twitter_id = $response->screen_name;
     $user = ORM::factory('user')->where('username', '=', $twitter_id)->find();
     !$user->id and Request::instance()->redirect('/auth/confirm?id=' . $twitter_id);
     Auth::instance()->force_login($user);
     Session::instance()->set('notification', 'Succesfully logged in.');
     Request::instance()->redirect('/');
 }
Ejemplo n.º 21
0
 public function action_index()
 {
     $prod_url = $this->param('product');
     $this->set_metatags_and_content($prod_url, 'product');
     $reviews = ORM::factory('Reviews')->getReviewsByProdId($this->_model->id);
     $reviews_count = ORM::factory('Reviews')->countReviewsByProdId($this->_model->id);
     $rating = ORM::factory('Reviews')->countRatingByProdId($this->_model->id);
     $related = ORM::factory('Product')->fetchProdRelated($this->_model->category, $this->_model->id);
     Cookie::set("products[{$this->_model->id}]", true);
     $PDO = ORM::factory('Product')->PDO();
     $color = $PDO->query("SELECT color FROM product WHERE id = '{$this->_model->id}'")->fetch(PDO::FETCH_ASSOC);
     $volume_test = $PDO->query("SELECT volume, id, price, new_price, article FROM product WHERE parent_product = '{$this->_model->id}' OR id = '{$this->_model->id}'")->fetchAll(PDO::FETCH_ASSOC);
     $volume_prod = ORM::factory('Product')->fetchProdVolume($this->_model->id)->as_array();
     $this->template->volume_test = $volume_test;
     $this->template->volume_prod = $volume_prod;
     $this->template->rating = $rating;
     $this->template->reviews_count = $reviews_count;
     $this->template->reviews = $reviews;
     $this->template->brand = $this->_model->brand;
     $this->template->category = $this->_model->category;
     $this->template->colors = $color['color'];
     $this->template->related = $related;
     $this->template->set_layout('layout/site/global');
     $this->template->s_title = $this->_model->name . ' - купить ' . $this->template->category->name . ' в Минске в интернет магазине cosm.by: лучшие цены, большой каталог, отзывы';
 }
Ejemplo n.º 22
0
 /**
  * @return UserSession|bool
  * @throws \Kohana_Exception
  */
 public static function Check()
 {
     $conf = \Kohana::$config->load('session')->get('native');
     $condition = (new \DBCriteria())->addColumnCondition(['ip' => \Request::$client_ip, 'iduser' => \Session::instance()->get('user_id', false), 'token' => self::getToken()])->addCondition('`expired`>=UNIX_TIMESTAMP(NOW())');
     /** @var $dbSession UserSession */
     $dbSession = UserSession::model()->find($condition);
     //if we not found row in BD
     if (is_null($dbSession)) {
         return false;
     }
     //If session key destroy in Cookie and Session(memcahed)
     if (!\Cookie::get('user_token', false) and !\Session::instance()->get('user_token', false)) {
         $dbSession->expired = time() + $conf['lifetime'];
         if ($dbSession->save()) {
             \Session::instance()->set('user_id', $dbSession->id);
             \Cookie::set('user_token', $dbSession['token'], time() + $conf['lifetime']);
             \Session::instance()->set('user_token', $dbSession['token']);
             return $dbSession;
             //return true;
         } else {
             \Kohana::$log->add(\Log::WARNING, 'Error to update session in [ID#' . $dbSession->owner->login . ']');
             return true;
         }
     } else {
         if (\Cookie::get('user_token', false) !== \Session::instance()->get('user_token', false)) {
             \Kohana::$log->add(\Log::WARNING, 'Session Key <> Cookie Key');
         }
         $expired = time() + $conf['lifetime'];
         $dbSession->expired = $expired;
         $dbSession->save(false);
         \Cookie::set('user_token', $dbSession->token, $expired);
         return $dbSession;
     }
 }
Ejemplo n.º 23
0
 /**
  * 确认注册【设定密码】
  * @method registerAction
  * @return [type]         [description]
  * @author NewFuture
  */
 public function registerAction()
 {
     $msg = '信息注册失败!';
     if ($regInfo = Session::get('reg')) {
         Session::del('reg');
         if (Input::post('password', $password, 'trim') === false) {
             /*密码未md5*/
             $this->error('密码错误', '/');
         } elseif (!$password) {
             /*未设置密码*/
             $password = $regInfo['password'];
         }
         $regInfo['password'] = Encrypt::encryptPwd($password, $regInfo['number']);
         if ($id = UserModel::insert($regInfo)) {
             /*注册成功*/
             $regInfo['id'] = $id;
             $token = Auth::token($regInfo);
             Cookie::set('token', [$id => $token]);
             unset($regInfo['password']);
             Session::set('user', $regInfo);
             $msg = '信息注册成功!';
         }
     }
     $this->jump('/', $msg);
 }
Ejemplo n.º 24
0
 /**
  * Checks POSTed data for CSRF token validity
  */
 static function detect()
 {
     $CSRF = !isset($_POST[self::$_cookieKey]) || !Cookie::exists(self::$_cookieKey) || $_POST[self::$_cookieKey] !== Cookie::get(self::$_cookieKey);
     if (!POST_REQUEST && $CSRF) {
         Cookie::set(self::$_cookieKey, md5(time() + rand()), Cookie::SESSION);
     }
 }
Ejemplo n.º 25
0
 public function before()
 {
     if ($this->request->action === 'media') {
         // Do not template media files
         $this->auto_render = FALSE;
     } else {
         // Grab the necessary routes
         $this->media = Route::get('docs/media');
         $this->api = Route::get('docs/api');
         $this->guide = Route::get('docs/guide');
         if (isset($_GET['lang'])) {
             $lang = $_GET['lang'];
             // Load the accepted language list
             $translations = array_keys(Kohana::message('userguide', 'translations'));
             if (in_array($lang, $translations)) {
                 // Set the language cookie
                 Cookie::set('userguide_language', $lang, Date::YEAR);
             }
             // Reload the page
             $this->request->redirect($this->request->uri);
         }
         // Set the translation language
         I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
         // Use customized Markdown parser
         define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
         // Load Markdown support
         require Kohana::find_file('vendor', 'markdown/markdown');
         // Set the base URL for links and images
         Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
         Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
     }
     parent::before();
 }
Ejemplo n.º 26
0
 public function index()
 {
     $html_tree .= $this->next_organizational(0);
     $this->assign('html_tree', $html_tree);
     Cookie::set('_currentUrl_', __SELF__);
     $this->display();
 }
Ejemplo n.º 27
0
 public function ajaxAddProblemAction()
 {
     $setId = Request::getPOST('set-id');
     $remote = Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     // 默认题库
     Cookie::set('default_remote', $remote);
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if ($problemInfo['hidden']) {
         $this->renderError('无法添加隐藏的题目!');
     }
     $setInfo = OjProblemSetInterface::getById(array('id' => $setId));
     if (empty($setInfo)) {
         $this->renderError('专题不存在!');
     }
     // 属主验证
     if ($this->loginUserInfo['id'] != $setInfo['user_id']) {
         $this->renderError('你没有权限操作!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经在专题中!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjProblemSetInterface::addProblem(array('id' => $setId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功');
     $this->renderAjax(0);
 }
Ejemplo n.º 28
0
 /**
  * 科目设置
  * 
  * @author 管理员
  * @date  2012-12-04
  */
 public function kmsz_list()
 {
     $finances_cat_tree = $this->finances_cat_tree(0);
     $this->assign('finances_cat_tree', $finances_cat_tree);
     Cookie::set('_currentUrl_', __SELF__);
     $this->display();
 }
Ejemplo n.º 29
0
 public function before()
 {
     parent::before();
     // Borrowed from userguide
     if (isset($_GET['lang'])) {
         $lang = $_GET['lang'];
         // Make sure the translations is valid
         $translations = Kohana::message('langify', 'translations');
         if (in_array($lang, array_keys($translations))) {
             // Set the language cookie
             Cookie::set('langify_language', $lang, Date::YEAR);
         }
         // Reload the page
         $this->request->redirect($this->request->uri());
     }
     // Set the translation language
     I18n::$lang = Cookie::get('langify_language', Kohana::config('langify')->lang);
     // Borrowed from Vendo
     // Automaticly load a view class based on action.
     $view_name = $this->view_prefix . Request::current()->action();
     if (Kohana::find_file('classes', strtolower(str_replace('_', '/', $view_name)))) {
         $this->view = new $view_name();
         $this->view->set('version', $this->version);
     }
 }
Ejemplo n.º 30
0
Archivo: jx.php Proyecto: jonlb/JxCMS
 /**
  * Logs a user in.
  *
  * @param   string   username
  * @param   string   password
  * @param   boolean  enable auto-login
  * @return  boolean
  */
 public function _login($user, $password, $remember)
 {
     // Make sure we have a user object
     //Jx_Debug::dump($user,'User passed in');
     $user = $this->_get_object($user);
     //Jx_Debug::dump(null,'In _login');
     //Jx_Debug::dump($user->password,'User password after getting object');
     //Jx_Debug::dump($password,'Password passed in');
     // If the passwords match, perform a login
     if (Jx_Acl::check_for_cap('allow_login', $user) and $user->password === $password) {
         if ($remember === TRUE) {
             // Create a new autologin token
             $token = Model::factory('user_token');
             // Set token data
             $token->user = $user->id;
             $token->expires = time() + $this->_config['lifetime'];
             $token->create();
             // Set the autologin Cookie
             Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
         }
         // Finish the login
         //Jx_Debug::dump(null, 'finishing login');
         $this->complete_login($user);
         return TRUE;
     }
     // Login failed
     return FALSE;
 }