public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { $config = \Yaf_Registry::get('configarr'); $dispatcher = Yaf_Dispatcher::getInstance(); $twig = ''; // view 放在module 目录里 if ($request->module == $config['application']['dispatcher']['defaultModule']) { $twig = new \Core_Twig(APP_PATH . 'views', $config['twig']); } else { $twig = new \Core_Twig(APP_PATH . 'modules/' . $request->module . '/views', $config['twig']); } // url generate $twig->twig->addFunction("url", new Twig_Function_Function("Tools_help::url")); // 语言对应 $twig->twig->addFunction("lang", new Twig_Function_Function("Tools_help::lang")); // 图片路径 $twig->twig->addFunction("fbu", new Twig_Function_Function("Tools_help::fbu")); // 数字验证 $twig->twig->addFunction("is_numeric", new Twig_Function_Function("is_numeric")); // 处理错误提醒 $session_key = array('ErrorMessageStop', 'ErrorMessage', 'Message'); foreach ($session_key as $value) { $twig->assign($value, Tools_help::getSession($value)); Tools_help::setSession($value, ''); } $dispatcher->setView($twig); }
/** * 记住用户 * * */ public function reMemberMe($data, $isWriteCookie = false) { $temp = array('uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password'], 'role_type' => $data['role_type']); Tools_help::setSession('admin', $temp); // rememberme 记住密码 if ($isWriteCookie) { Tools_help::setCookie('admin', $temp, 24 * 60 * 60 * 7); } }
/** * 返回上一页并显示错误 * */ protected function error($msg, $type = 'ErrorMessage', $url = '') { // 验证失败 Tools_help::setSession($type, $msg); if ($url) { header("Location: " . $url); } else { if (isset($_SERVER['HTTP_REFERER'])) { header("Location: " . $_SERVER['HTTP_REFERER']); } else { $url = Tools_help::url(strtolower($this->moduleName) . '/' . strtolower($this->controllerName) . '/index'); header("Location: " . $url); } } $this->_exit(); }
/** * Run Opauth: * Parses request URI and perform defined authentication actions based based on it. */ public function run() { if (!empty($this->strategyName)) { if (array_key_exists($this->strategyName, $this->strategyMap)) { // 当前oauth配置 $strategy = $this->env['Strategy'][$this->strategyName]; // 当前oauth执行方法 if (!empty($this->strategyCallback)) { $this->strategyCallback = strtolower($this->strategyName) . '_callback'; $this->env['params']['action'] = $this->strategyCallback; } // 调用对应oauth类 $className = 'Oauth_Strategy_' . $this->strategyName; $safeEnv = $this->env; unset($safeEnv['Strategy']); $this->Strategy = new $className($strategy, $safeEnv); if (empty($this->env['params']['action'])) { $this->env['params']['action'] = 'request'; // 记录来源 S $referer = ''; if (isset($_GET['ref'])) { $referer = addslashes($_GET['ref']); } else { if (isset($_SERVER["HTTP_REFERER"])) { $referer = addslashes($_SERVER["HTTP_REFERER"]); } } if (!empty($referer)) { Tools_help::setSession('oauth_referer', $referer); } // 记录来源 E } // 调用oauth对应方法 $this->Strategy->callAction($this->env['params']['action']); } else { trigger_error('未定义的Oauth - ' . $this->env['params']['strategy'], E_USER_ERROR); } } }
public static function simple($len, $width = 48, $height = 22) { $words = self::words($len); $session_key = 'captcha'; //$_SESSION[$session_key] = strtolower($words); Tools_help::setSession($session_key, strtolower($words)); $width = $len * 10 + 10 > $width ? $len * 10 + 10 : $width; $canvas = imagecreatetruecolor($width, $height); $r = array(225, 255, 255, 223); $g = array(225, 236, 237, 255); $b = array(225, 236, 166, 125); $key = mt_rand(0, 3); $back = imagecolorallocate($canvas, $r[$key], $g[$key], $b[$key]); $border = imagecolorallocate($canvas, 100, 100, 100); imagefilledrectangle($canvas, 0, 0, $width - 1, $height - 1, $back); imagerectangle($canvas, 0, 0, $width - 1, $height - 1, $border); $string = imagecolorallocate($canvas, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); for ($i = 0; $i < 10; $i++) { imagearc($canvas, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 200), mt_rand(20, 200), 55, 44, $string); } for ($i = 0; $i < 25; $i++) { imagesetpixel($canvas, mt_rand(0, $width), mt_rand(0, $height), $string); } for ($i = 0; $i < $len; $i++) { imagestring($canvas, 5, $i * 10 + 5, mt_rand(1, 8), $words[$i], $string); } if ($canvas) { header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Pragma: no-cache"); header("Cache-control: private"); header('Content-Type: image/png'); imagepng($canvas); imagedestroy($canvas); } exit; }
/** * 编辑角色 * */ public function editAction() { // 获取主键 $id = $this->getg('id', 0); if (empty($id)) { $this->error('id 不能为空!'); } // 实例化Model $rbac = new Rbac_Core(); // 处理Post if ($this->getRequest()->isPost()) { $name = $this->getp('name'); $result = true; $errors = array(); if (empty($name)) { $result = false; $errors['name'] = '角色名称不能为空!'; } else { $data = $rbac->getRole($name); if ($data && $data['id'] != $id) { $result = false; $errors['name'] = '角色名称已经存在!'; } } // 通过验证 if ($result) { $result = $rbac->editRole($id, $name); if ($result) { // 提示信息并跳转到列表 Tools_help::setSession('Message', '修改成功!'); $this->redirect('/backend/roles/index'); } else { // 验证失败 $this->_view->assign('ErrorMessage', '修改失败!'); } } else { // 验证失败 $this->_view->assign('ErrorMessage', '修改失败!'); $this->_view->assign("errors", $errors); } } if (empty($name)) { $data = $rbac->getRole($id); if ($data) { $name = $data['name']; } else { // 提示信息并跳转到列表 Tools_help::setSession('ErrorMessage', '没找到对应角色!'); $this->redirect('/backend/roles/index'); } } $this->_view->assign("name", $name); $this->_view->assign("id", $id); $this->_view->assign("pageTitle", '修改角色'); }
/** * 管理员退出 * */ public function logoutAction() { Tools_help::setSession('member', ''); Tools_help::setCookie('member', '', 0); $this->redirect('/backend/login/index'); }
/** * 编辑 * */ public function editAction() { // 获取主键 $id = $this->getg('id', 0); if (empty($id)) { $this->error('id 不能为空!'); } // 实例化Model $log = new LogModel(); // 处理Post if ($this->getRequest()->isPost()) { // 获取所有post数据 $pdata = $this->getAllPost(); // 处理图片等特殊数据 // 验证 $result = $log->validation->validate($pdata, 'edit'); $log->parseAttributes($pdata); // 通过验证 if ($result) { // 入库前数据处理 // Model转换成数组 $data = $log->toArray($pdata); $result = $log->update(array('id' => $id), $data); if ($result) { // 提示信息并跳转到列表 Tools_help::setSession('Message', '修改成功!'); $this->redirect('/backend/log/index'); } else { // 出错 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!'); $this->_view->assign("errors", $log->validation->getErrorSummary()); } $log->id = $id; } else { // 验证失败 Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项'); $this->_view->assign("errors", $log->validation->getErrorSummary()); } } // 如果Model数据为空,则获取 if (!empty($id) && empty($log->id)) { $data = $log->select(array('where' => array('id' => $id))); $log->parseAttributes($data); } // 格式化表单数据 // 模版分配数据 $this->_view->assign("log", $log); $this->_view->assign("pageTitle", '修改'); }
/** * Send $data to callback_url using specified transport method * * @param array $data Data to be sent * @param string $transport Callback method, either 'get', 'post' or 'session' * 'session': Default. Works best unless callback_url is on a different domain than Opauth * 'post': Works cross-domain, but relies on availability of client-side JavaScript. * 'get': Works cross-domain, but may be limited or corrupted by browser URL length limit * (eg. IE8/IE9 has 2083-char limit) * */ private function shipToCallback($data, $transport = null) { if (empty($transport)) { $transport = $this->env['callback_transport']; } switch ($transport) { case 'get': $this->redirect($this->env['callback_url'] . '?' . http_build_query(array('opauth' => base64_encode(serialize($data))), '', '&')); break; case 'post': $this->clientPost($this->env['callback_url'], array('opauth' => base64_encode(serialize($data)))); break; case 'session': default: Tools_help::setSession('oauth', $data); $this->redirect($this->env['callback_url']); } }
/** * 编辑新闻 * */ public function editAction() { // 获取主键 $id = $this->getg('id', 0); if (empty($id)) { $this->error('id 不能为空!'); } // 实例化Model $news = new NewsModel(); // 处理Post if ($this->getRequest()->isPost()) { // 获取所有post数据 $pdata = $this->getAllPost(); // 处理图片等特殊数据 $imageInfo = Tools_help::upload('img', 'news'); if (!empty($imageInfo)) { $pdata['img'] = $imageInfo; } else { unset($pdata['img']); } // 验证 $result = $news->validation->validate($pdata, 'edit'); $news->parseAttributes($pdata); // 通过验证 if ($result) { // 入库前数据处理 $pdata['dateline'] = Tools_help::htime($news->dateline); $pdata['updatetime'] = Tools_help::htime($news->updatetime); // Model转换成数组 $data = $news->toArray($pdata); $result = $news->update(array('id' => $id), $data); if ($result) { // 提示信息并跳转到列表 Tools_help::setSession('Message', '修改成功!'); $this->redirect('/backend/news/index'); } else { // 出错 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!'); $this->_view->assign("errors", $news->validation->getErrorSummary()); } $news->id = $id; } else { // 验证失败 Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项'); $this->_view->assign("errors", $news->validation->getErrorSummary()); } } // 如果Model数据为空,则获取 if (!empty($id) && empty($news->id)) { $data = $news->select(array('where' => array('id' => $id))); $news->parseAttributes($data); } // 格式化表单数据 // 图片处理 if ($news->img) { $news->img = Tools_help::fbu($news->img); } // 模版分配数据 $this->_view->assign("news", $news); $this->_view->assign("pageTitle", '修改新闻'); }
/** * 编辑用户表 * */ public function editAction() { // 获取主键 $uid = $this->getg('uid', 0); if (empty($uid)) { $this->error('uid 不能为空!'); } // 实例化Model $members = new MembersModel(); // 处理Post if ($this->getRequest()->isPost()) { // 获取所有post数据 $pdata = $this->getAllPost(); // 处理图片等特殊数据 $imageInfo = Tools_help::upload('face', 'members'); if (!empty($imageInfo)) { $pdata['face'] = $imageInfo; } else { unset($pdata['face']); } // 验证 $result = $members->validation->validate($pdata, 'edit'); $members->parseAttributes($pdata); // 用户名验证 $data = $members->select(array('where' => array('username' => $members->username))); if ($data && $data['uid'] != $uid) { $result = false; $members->validation->errors['username'][] = '用户名 已经存在,请重新填写!'; } // 通过验证 if ($result) { // 入库前数据处理 $pdata['regdate'] = Tools_help::htime($members->regdate); $pdata['password'] = Tools_help::hash($members->password); // Model转换成数组 $data = $members->toArray($pdata); $result = $members->update(array('uid' => $uid), $data); if ($result) { // 提示信息并跳转到列表 Tools_help::setSession('Message', '修改成功!'); $this->redirect('/backend/members/index'); } else { // 出错 Tools_help::setSession('ErrorMessage', '修改失败, 请确定已修改了某项!'); $this->_view->assign("errors", $members->validation->getErrorSummary()); } } else { // 验证失败 Tools_help::setSession('ErrorMessage', '修改失败, 请检查错误项'); $this->_view->assign("errors", $members->validation->getErrorSummary()); } $members->uid = $uid; } // 如果Model数据为空,则获取 if (!empty($uid) && empty($members->uid)) { $data = $members->select(array('where' => array('uid' => $uid))); $members->parseAttributes($data); } // 图片处理 if ($members->face) { $members->face = Tools_help::fbu($members->face); } // 模版分配数据 $this->_view->assign("members", $members); $this->_view->assign("pageTitle", '修改用户表'); }