Exemple #1
0
 public function __construct(array $config = null, $id = null)
 {
     if (!isset($config['cache'])) {
         $config['cache'] = 'default';
     }
     $this->cache = \Cache\Cache::ins($config['cache']);
     parent::__construct($config, $id);
 }
Exemple #2
0
 public function loadFlash()
 {
     $this->flash_memory = array();
     if (Session::issetKey(self::$flash_key)) {
         $this->flash_memory = Session::get(self::$flash_key);
         Session::unsetKey(self::$flash_key);
     }
 }
Exemple #3
0
 /**
  * @brief 校验是否有效token
  *
  * @param $token string 待检查token
  *
  * @return boolean
  */
 public static function check($token)
 {
     //读取已存在token
     $exist = Session::ins()->get(self::TOKEN_NAME);
     if (!$exist || !is_array($exist)) {
         return false;
     }
     $key = array_search($token, $exist, true);
     if ($key !== false) {
         //校验成功删除对应token
         unset($exist[$key]);
         //保存token
         Session::ins()->set(self::TOKEN_NAME, $exist);
         return true;
     } else {
         return false;
     }
 }
Exemple #4
0
 public function getUserLanguage()
 {
     // 		$serverArray = explode(".", SERVER);
     if (isset($_GET['l'])) {
         $l = $_GET['l'];
         \session\Session::set('lang', $l);
         // 		} else if(in_array($serverArray[0], $this->valid_languages)) {
         // 			$l = $serverArray[0];
     } else {
         if (\session\Session::issetKey('lang')) {
             $l = \session\Session::get('lang');
         } else {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $l = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
             } else {
                 $l = "es";
             }
         }
     }
     return $l;
 }
Exemple #5
0
 public function profile(ProfilesRequest $request)
 {
     //if user not login
     if (!Auth::check()) {
         redirect();
     }
     //update session if have change
     Auth::update();
     $session = new Session();
     $user_news_data = null;
     if ($request->act === 'news') {
         $model = new Data();
         // valied request. Request class have much bug ~.~
         if (!is_numeric($request->page) || !is_numeric($request->perpage) || $request->page < 0 || $request->perpage < 0) {
             //set default value
             $user_news_data = $model->getList(Auth::user()->id, 1, 20);
         } else {
             $user_news_data = $model->getList(Auth::user()->id, $request->page, $request->perpage);
         }
     }
     $var = ['nav_view_top' => $this->getNavTop(), 'profiles_body' => $this->getProfilesBody($request->act), 'email' => empty($session->get('email')) ? 'Chưa cập nhật' : $session->get('email'), 'fullname' => empty($session->get('name')) ? 'Chưa cập nhật' : $session->get('name'), 'birthday' => empty($session->get('birthday')) ? 'Chưa cập nhật' : $session->get('birthday'), 'gender' => $session->get('gender') === null ? 'Chưa cập nhật' : $session->get('gender') == 1 ? 'Nữ' : 'Nam', 'address' => empty($session->get('address')) ? 'Chưa cập nhật' : $session->get('address'), 'mobile' => empty($session->get('mobile')) ? 'Chưa cập nhật' : $session->get('mobile'), 'u_id' => empty($session->get('id')) ? null : $session->get('id'), 'u_news_data' => $user_news_data];
     return view('profiles', $var);
 }
Exemple #6
0
 /**
  * 生成验证码
  * @param string $id  唯一标识
  */
 public function entry($id = '')
 {
     $now_time = time();
     #验证码长宽设置
     $this->imageW || ($this->imageW = $this->length * $this->fontSize * 1.5 + $this->length * $this->fontSize / 2);
     $this->imageH || ($this->imageH = $this->fontSize * 2.5);
     # 新建画布
     $this->image = imagecreate($this->imageW, $this->imageH);
     # 设置背景色
     imagecolorallocate($this->image, $this->bg[0], $this->bg[1], $this->bg[2]);
     # 验证码使用随机字体
     $ttfPath = dirname(__FILE__) . '/ttfs';
     if (empty($this->fontttf)) {
         $dir = dir($ttfPath);
         $ttfs = array();
         while (false !== ($file = $dir->read())) {
             if ($file[0] != '.' && substr($file, -4) == '.ttf') {
                 $ttfs[] = $file;
             }
         }
         $dir->close();
         $this->fontttf = $ttfs[array_rand($ttfs)];
     }
     $this->fontttf = $ttfPath . '/' . $this->fontttf;
     # 开始绘制验证码
     $code = array();
     $codeNX = 0;
     for ($i = 0; $i < $this->length; $i++) {
         # 验证码字体随机颜色
         $color = imagecolorallocate($this->image, mt_rand(1, 150), mt_rand(1, 150), mt_rand(1, 150));
         $code[$i] = $this->codeSet[mt_rand(0, strlen($this->codeSet) - 1)];
         $codeNX += mt_rand($this->fontSize * 1.2, $this->fontSize * 1.3);
         imagettftext($this->image, $this->fontSize, mt_rand(-20, 20), $codeNX, $this->fontSize * 1.5, $color, $this->fontttf, $code[$i]);
     }
     #干扰线
     if ($this->useLine) {
         $this->writeLine();
     }
     # 保存验证码
     $key = $this->authcode($this->keySet);
     $code = $this->authcode(implode('', $code));
     $secode = array();
     $secode['verify_code'] = $code;
     $secode['verify_time'] = $now_time;
     Session::set($key . $id, $secode);
     header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
     header('Cache-Control: post-check=0, pre-check=0', false);
     header('Pragma: no-cache');
     header("content-type: image/png");
     # 输出图像
     imagepng($this->image);
     imagedestroy($this->image);
 }
Exemple #7
0
 protected function pushError($error)
 {
     $errors = Session::get('errors');
     if (!$errors) {
         $errors = array();
     }
     if (is_array($error)) {
         foreach ($error as $e) {
             $errors[] = $e;
         }
     } else {
         $errors[] = $error;
     }
     Session::set('errors', $errors);
 }
Exemple #8
0
<?php

use session\Session;
View::addTemplatesDir(__DIR__ . "/views");
Controller::addControllersDir(__DIR__ . "/controllers");
Doctrine_Core::loadModels(dirname(__FILE__) . '/models');
\hook\Hook::add("controller_construct_end", function ($key, $controller) {
    session_name(COOKIE_PREFIX . "login");
    session_save_path(__DIR__ . "/sessions");
    session_start();
    $usertable = Doctrine::getTable("User");
    $user = Session::issetKey('id_user') ? $usertable->find(Session::get('id_user')) : false;
    if (!$user) {
        $user = new User();
    }
    $controller->user = $user;
    User::$logged_user = $user;
    $controller->isLoggedIn = User::isLoggedIn();
    $controller->isAdmin = User::isAdmin();
});
 /**
  *清空认证信息
  */
 public function clear()
 {
     \session\Session::delete($this->namesapce);
 }
Exemple #10
0
 /**
  * @param $tpl
  *
  * @return mixed|string
  */
 public function fetch($tpl)
 {
     $view_dir = $this->getViewDir();
     $view = $view_dir . '/' . $tpl . '.php';
     ob_start();
     if (!empty($this->header)) {
         $header = $this->header . '.php';
         if (is_file($header)) {
             require $header;
         }
     }
     require $view;
     if (!empty($this->footer)) {
         $footer = $this->footer . '.php';
         if (is_file($footer)) {
             require $footer;
         }
     }
     $data = ob_get_contents();
     ob_end_clean();
     if ($this->ob_data != '') {
         $data = $this->ob_data . $data;
     }
     #form添加token,防止表单重复提交
     $token = md5(uniqid('token'));
     $sess_token = Session::get('token');
     if (!$sess_token) {
         $sess_token = array($token);
     } elseif (is_array($sess_token)) {
         $sess_token[] = $token;
     } else {
         $sess_token = array($sess_token, $token);
     }
     Session::set('token', $sess_token);
     $data = preg_replace('/<\\/form>/', "<input type=\"hidden\" name=\"token\" value=\"{$token}\" />\n</form>", $data);
     return $data;
 }
Exemple #11
0
<?php

include_once '../vendor/autoload.php';
use session\Session;
use MongoClient;
$client = new MongoClient("mongodb://localhost:27017");
$db = $client->selectDB("session-mongo-test");
Session::setMongoHandler($db);
$session = Session::singleton();
Exemple #12
0
 private function loadRegistry()
 {
     \Registry::set('config', \NdkSolution\Config::getInstance());
     \Registry::set('session', \Session\Session::getInstance());
     \Registry::set('security', \Security\Security::getInstance());
 }
Exemple #13
0
 /**
  * @return void
  */
 public function __construct()
 {
     $this->_session = Session::instance();
 }
 function logout()
 {
     Session::unsetKey("id_user");
     //setcookie(COOKIE_PREFIX."login", "", time()-36000000, "/");
     header("Location: " . ROOT);
 }
Exemple #15
0
 public function redirect($url)
 {
     Session::transferFlash();
     $this->status_code = 302;
     $this->http_headers = array('Location' => $url);
     $this->responseCode();
     $this->responseHeaders();
     die;
 }