public function get($key = '') { if ($this->aliasToRedis) { $myCacher = new Cacher($key, Cacher::STORAGE_REDIS); return $myCacher->get(); } else { return false; } }
/** * Test if a cache is available and (if yes) return it. * * @param string $id Cache id * @return mixed */ public function get($id, $opt = 0) { $data = $this->doGet($id, $opt); if (!isset($data) && isset($this->chainNext) && ~$opt & self::NOCASCADE) { $data = $this->chainNext->get($id, $opt); if (isset($data)) { $this->doSave($id, $data, $opt); } } return $data; }
public function getArticles() { if (Input::has('firstArticleID')) { $latest = Cacher::get(LATEST_ARTICLE_ID_KEY); if (Input::get('firstArticleID') >= $latest) { return $this->jsonResponse(array()); } } $articleList = new ArticleList(); $articleList->load(); return $this->jsonResponse($articleList->data); }
public static function create($token, $width, $height) { /*{{{*/ $self = new CaptchaSketchpad(); $cacher = Cacher::get()->getCache(Cacher::CACHETYPE_CAPTCHA); $originalValues = $cacher->get($token); $self->displayStr = $originalValues['question']; $self->width = $width; $self->height = $height; $self->img = imagecreate($width, $height); imagecolorallocate($self->img, 238, 238, 238); return $self; }
public static function generateByDefaultKey($app, $captchaType, $charCnt, $clientIp, $effactiveTime) { /*{{{*/ DBC::requireTrue($effactiveTime < 60, "有效时间不能超过1小时"); $contentObj = ContentFactory::generate($captchaType); $contentArr = $contentObj->generate($charCnt); $handler = new QBase64(); $key = self::generateID(); $token = $handler->crypt(microtime() . $app . $key); $expireTime = XDateTime::now()->addMinute($effactiveTime)->getTime(); $originalValues = array('app' => $app, 'key' => $key, 'ip' => $clientIp, 'expiretime' => $expireTime, 'answer' => strtolower($contentArr['answer']), 'question' => $contentArr['question']); $cacher = Cacher::get()->getCache(Cacher::CACHETYPE_CAPTCHA); $cacher->add($token, $originalValues); return array('token' => $token, 'captchaId' => $key); }
public function getCache($type) { return Cacher::get()->getCache($type); }
private function loadFromCache() { $this->data = Cacher::get(FEED_CACHE_KEY); }
public function doFindPwdVerifyKey($request, $response) {/*{{{*/ if (Captcha::verify($request->key, XIpLocation::getIp(), 'password', $request->mobile, $request->token)) { $newToken = Captcha::generate('password', $request->mobile, ContentFactory::TYPE_NUM, 4, XIpLocation::getIp(), 10); $cacher = Cacher::get()->getCache(Cacher::CACHETYPE_CAPTCHA); $captchaInfos = $cacher->get($newToken); $newKey = strtolower($captchaInfos['question']); if(stripos($request->forward, 'weixUserId') === 0) { $nextUrl = $response->router->urlfor('weixin/afterfinduserpwd').'?'.$request->forward; $results = array('res' => 'success', 'msg' => '', 'next' => $nextUrl, 'forward' => $request->forward); } else { $results = array('res' => 'success', 'msg' => '', 'next' => $response->router->urlfor('user/findpwd', array('userId' => $request->userId, 'mobile' => $request->mobile,'key' => $newKey, 'token' => $newToken, 'forward' => $request->forward))); } } else { $results = array('res' => 'failure', 'msg' => mb_convert_encoding('验证码输入有误', 'UTF-8', 'GBK'), 'next' => ''); } echo json_encode($results); return self::DIRECT_OUTPUT; }/*}}}*/
public function domobileBindUser($request, $response) {/*{{{*/ if (Captcha::verify($request->key, XIpLocation::getIp(), 'password', $request->mobile, $request->token)) { $newToken = Captcha::generate('password', $request->mobile, ContentFactory::TYPE_NUM, 4, XIpLocation::getIp(), 10); $cacher = Cacher::get()->getCache(Cacher::CACHETYPE_CAPTCHA); $captchaInfos = $cacher->get($newToken); $newKey = strtolower($captchaInfos['question']); $bindRes = WeixClient::getInstance()->bindUser($this->weixSpaceUser->id,$request->spaceId, WeixUser::WEIXINTYPE_SPACE); if($bindRes == true ) { $user = UserClient::getInstance()->login4Weix($request->spaceId); $res = "success"; $forward = (empty($forward)) ? $response->router->urlfor('weixindoctor/bindsuccess') : $forward; } else { $res = "hasbind"; //该用户已绑定 } $results = array('res' => $res, 'msg' => ''); } else { $results = array('res' => 'failure', 'msg' => mb_convert_encoding('验证码输入有误', 'UTF-8', 'GBK'), 'next' => ''); } echo json_encode($results); return self::DIRECT_OUTPUT; }/*}}}*/
public function confirmPassword($request, $response) {/*{{{*/ DBC::requireNotEmptyString($request->username, 'username不能为空'); DBC::requireNotEmptyString($request->key, '验证码不能为空'); $response->title = '取回密码_好大夫'; $response->message = ''; $response->user = DAL::get()->find_by_name('user', $request->username); if ($request->isPost() == false) { if('email' == $request->type) { $verifyOk = Captcha::verifyKey($request->key, $response->user->id); DBC::requireTrue($verifyOk, '验证码错误, 请重新找回密码'); } else { $verifyOk = Captcha::verify($request->key, XIpLocation::getIp(), 'password', md5($request->username), $request->token); DBC::requireTrue($verifyOk, '验证码错误, 请重新找回密码'); } $newToken = Captcha::generate('password', md5($request->username), ContentFactory::TYPE_CHAR, 4, XIpLocation::getIp(), 10); $cacher = Cacher::get()->getCache(Cacher::CACHETYPE_CAPTCHA); $captchaInfos = $cacher->get($newToken); $response->key = $captchaInfos['question']; $response->token = $newToken; } if (false == $response->user->isNull()) { if ($request->isPost()) { $verifyOk = Captcha::verify($request->key, XIpLocation::getIp(), 'password', md5($request->username), $request->token); DBC::requireTrue($verifyOk, '验证码错误, 请重新找回密码'); DBC::requireNotEmptyString($request->password, '新密码不能为空'); DBC::requireNotEmptyString($request->confirmPassword, '确认密码不能为空'); DBC::requireEquals($request->password, $request->confirmPassword, '密码和确认密码不一致'); UserClient::getInstance()->updatePassword($response->user->id, $request->password); $response->setRedirect($response->router->urlfor('user/login', array('forward'=>$request->forward))); } } else { throw new BizException('取回密码过期,请重新取回'); } }/*}}}*/
public function needRefresh() { return $this->isRecentArticle() && !Cacher::get($this->upToDateKey); }
public function banipRemove($ipaddress) { if ($this->isMemoryCacheEnable()) { $myCacher = new Cacher(self::PHPIDS_BANNEDIP_KEY); $list = $myCacher->get(); if (empty($list)) { return false; } else { $newlist = array(); foreach ($list as $ip) { if ($ip != $ipaddress) { $newlist[] = $ip; } } return $myCacher->set($newlist, 0); } } else { return false; } }