/** *验证是否登录:判断已登录条件:存在session['login']、session中user_id的用户session_id字段等于session_id()、session_id()未过期 * @param object $obj 控制器实例 * @return bool 是否登录 */ public function checkLogin($obj = null) { $sessID = session_id(); $sessLogin = session::get('login'); $isLogin = false; //判断是否登录以及登录是否超时 if ($sessLogin != null && isset($sessLogin['user_id']) && $sessID != '') { $userModel = new M('user'); $login_sessID = $userModel->where(array('id' => $sessLogin['user_id']))->getField('session_id'); if ($sessID == $login_sessID && self::$sessObj->expire($sessID)) { $isLogin = true; } } if ($obj !== null) { if ($isLogin == false) { //如果未登录或超时,登出操作,跳转到登录页 //$this->logOut(); $controller = $obj->getRequest()->getControllerName(); $action = $obj->getRequest()->getActionName(); $callBack = url::createUrl('/' . $controller . '/' . $action); $obj->redirect(url::createUrl('/index/login@user') . '?callback=' . $callBack); exit; } else { //已登录则记录user_id $obj->user_id = $sessLogin['user_id']; $obj->user_type = $sessLogin['type']; } } return $isLogin; }
/** * @brief 构造函数 * @param array $params 参数数组 * */ public function __construct($params = array()) { $this->path = url::getBaseUrl() . '/js/swfupload/'; $this->submit = isset($params['upload_url']) ? url::createUrl($params['upload_url']) : 'ucenter/upload'; $this->buttonID = isset($params['button_placeholder_id']) ? $params['button_placeholder_id'] : 'uploadButton'; if (isset($params['button_action']) && $params['button_action'] == -100) { $this->buttonAction = -100; } //单图上传 $this->imgContainer = isset($params['imgContainer']) ? $params['imgContainer'] : 'imgContainer'; $this->rand = rand(1, 9); }
/** * 登录处理 */ public function doLogAction() { $account = safe::filterPost('account'); $password = $_POST['password']; $captcha = safe::filterPost('captcha', '/^[a-zA-Z]{4}$/'); $data = array('errorCode' => 0); $captchaObj = new captcha(); if ($account == '') { $data['errorCode'] = 1; } else { if ($password == '') { $data['errorCode'] = 2; } else { if ($captcha == '') { $data['errorCode'] = 3; } else { if (!$captchaObj->check($captcha)) { //验证码是否正确 $data['errorCode'] = 4; } else { $userModel = new UserModel(); $userData = $userModel->checkUser($account, $password); if (empty($userData)) { //账户密码错误 $data['errorCode'] = 5; } else { //登录成功 $checkRight = new checkRight(); $checkRight->loginAfter($userData); } } } } } $data['returnUrl'] = isset($_POST['callback']) && $_POST['callback'] != '' ? trim($_POST['callback']) : url::createUrl('/'); echo JSON::encode($data); return false; }
/** * 解析模板标签 * @param $matches * @return string */ private function translate($matches) { if ($matches[1] !== '/') { switch ($matches[2] . $matches[3]) { case '$': $str = trim($matches[4]); $first = $str[0]; if ($first != '.' && $first != '(') { if (strpos($str, ')') === false) { return '<?php echo isset($' . $str . ')?$' . $str . ':"";?>'; } else { return '<?php echo $' . $str . ';?>'; } } else { return $matches[0]; } case 'echo:': return '<?php echo ' . rtrim($matches[4], ';/') . ';?>'; case 'if:': return '<?php if(' . $matches[4] . '){?>'; case 'elseif:': return '<?php }elseif(' . $matches[4] . '){?>'; case 'else:': return '<?php }else{' . $matches[4] . '?>'; case 'set:': return '<?php ' . $matches[4] . '; ?>'; case 'while:': return '<?php while(' . $matches[4] . '){?>'; case 'foreach:': $attr = $this->getAttrs($matches[4]); if (!isset($attr['items'])) { $attr['items'] = '$items'; } if (!isset($attr['key'])) { $attr['key'] = '$key'; } if (!isset($attr['item'])) { $attr['item'] = '$item'; } return '<?php foreach(' . $attr['items'] . ' as ' . $attr['key'] . ' => ' . $attr['item'] . '){?>'; case 'for:': $attr = $this->getAttrs($matches[4]); if (!isset($attr['item'])) { $attr['item'] = '$i'; } if (!isset($attr['from'])) { $attr['from'] = 0; } if (!isset($attr['upto']) && !isset($attr['downto'])) { $attr['upto'] = 10; } if (isset($attr['upto'])) { $op = '<='; $end = $attr['upto']; if ($attr['upto'] < $attr['from']) { $attr['upto'] = $attr['from']; } if (!isset($attr['step'])) { $attr['step'] = 1; } } else { $op = '>='; $end = $attr['downto']; if ($attr['downto'] > $attr['from']) { $attr['downto'] = $attr['from']; } if (!isset($attr['step'])) { $attr['step'] = -1; } } return '<?php for(' . $attr['item'] . ' = ' . $attr['from'] . ' ; ' . $attr['item'] . $op . $end . ' ; ' . $attr['item'] . ' = ' . $attr['item'] . '+' . $attr['step'] . '){?>'; case 'url:': //解析url到编译文件中,后续再访问无需再次解析 return url::createUrl(trim($matches[4])); case 'views:': //模板目录 return url::getViewDir() . trim(trim($matches[4]), '/'); break; case 'root:': //根目录 return url::getHost() . url::getScriptDir() . '/' . trim(trim($matches[4]), '/'); break; case 'area:': $attr = $this->getAttrs($matches[4]); if (!isset($attr['data'])) { $attr['data'] = '000000'; } if (!isset($attr['provinceID'])) { $attr['provinceID'] = 'seachprov'; } if (!isset($attr['cityID'])) { $attr['cityID'] = 'seachcity'; } if (!isset($attr['districtID'])) { $attr['districtID'] = 'seachdistrict'; } if (!isset($attr['inputName'])) { $attr['inputName'] = 'area'; } if (!isset($attr['pattern'])) { $attr['pattern'] = ''; } else { $attr['pattern'] = 'pattern="' . $attr['pattern'] . '"'; } if (!isset($attr['alt'])) { $attr['alt'] = '请选择地区'; } if (substr($attr['data'], 0, 1) == '$') { $attr['data'] = '<?php echo ' . $attr['data'] . ' ; ?>'; } return <<<OEF <script type="text/javascript"> {$attr['inputName']}Obj = new Area(); \$(function () { {$attr['inputName']}Obj.initComplexArea('{$attr['provinceID']}', '{$attr['cityID']}', '{$attr['districtID']}', '{$attr['data']}','{$attr['inputName']}'); }); </script> \t\t\t <select id="{$attr['provinceID']}" onchange=" {$attr['inputName']}Obj.changeComplexProvince(this.value, '{$attr['cityID']}', '{$attr['districtID']}');"> </select> <select id="{$attr['cityID']}" onchange=" {$attr['inputName']}Obj.changeCity(this.value,'{$attr['districtID']}','{$attr['districtID']}');"> </select> <span id='{$attr['districtID']}_div' > <select id="{$attr['districtID']}" onchange=" {$attr['inputName']}Obj.changeDistrict(this.value);"> </select></span> <input type="hidden" name="{$attr['inputName']}" {$attr['pattern']} alt="{$attr['alt']}" value='{$attr['data']}' /> OEF; break; default: return $matches[0]; } } else { if ($matches[2] == 'code') { return '?>'; } else { return '<?php }?>'; } } }