/** * 解密播放链接的解密串 * <pre> * return array( * 'tuid'=>0, //教程ID * 'tucid'=>0, //章节ID * 'uid'=>0, //用户ID * 'timestamp'=>0 //时间戳 * ); * </pre> * * @param string $_strKey * @return array */ public static function decodePlayKey($_strKey = "") { $strDecodeKey = CString::decode($_strKey, self::PLAY_KEY); $strDecodeKey = trim($strDecodeKey); $aryDecode = explode('|', $strDecodeKey); if (empty($aryDecode) || count($aryDecode) != 4) { throw new CModelException("无法解析的KEY!"); } //$aryTimestamp = explode('*',$aryDecode[3]); //$aryDecode[3] = $aryTimestamp[1]; return array('tuid' => $aryDecode[0], 'tucid' => $aryDecode[1], 'uid' => $aryDecode[2], 'timestamp' => $aryDecode[3]); }
/** * Index method */ public function actionLogin() { $objLoginModel = LoginModel::model(); try { //检查是否是post请求 $boolCheckLogin = false; if (Nbt::app()->request->isPostRequest) { // 绑定数据 $aryUserInfo['uname'] = isset($_POST['uname']) ? htmlspecialchars(trim($_POST['uname'])) : ''; $aryUserInfo['pwd'] = isset($_POST['pwd']) ? CString::encodeMachinePassword(trim($_POST['pwd'])) : ''; $strIsRemember = isset($_POST['remember']) ? htmlspecialchars(trim($_POST['remember'])) : 'no'; // 检查登录 $boolCheckLogin = LoginModel::model()->checkLogin($aryUserInfo); if ($boolCheckLogin === false) { throw new CModelException(CUtil::i18n('controllers,login_index_pwdWrong')); } //根据是否登入成功,再判断是否将用户名和密码写入cookie if ($boolCheckLogin === true && $strIsRemember === 'yes') { $aryUserInfo['pwd'] = CString::encode($aryUserInfo['pwd'], UKEY); //设置cookie,时间为一年 setcookie($this->_cookeName, base64_encode(json_encode($aryUserInfo)), time() + 365 * 24 * 3600); } } else { if (!empty($_COOKIE[$this->_cookeName]) && $boolCheckLogin === false) { $aryUserInfo = json_decode(base64_decode($_COOKIE[$this->_cookeName]), 1); $aryUserInfo['pwd'] = CString::decode($aryUserInfo['pwd'], UKEY); if (($boolCheckLogin = $objLoginModel->checkLogin($aryUserInfo)) === false) { throw new CModelException(CUtil::i18n('controllers,login_index_pwdWrong')); } } } //contains/判断是否登入成功 if ($boolCheckLogin === true) { Nbt::app()->session->set('userInfo', $aryUserInfo); UtilMsg::saveTipToSession(CUtil::i18n('controllers,login_index_success')); $this->redirect(array('index/index')); } } catch (CModelException $e) { UtilMsg::saveErrorTipToSession($e->getMessage()); } $this->layout = 'login'; $this->seoTitle = CUtil::i18n('controllers,login_index_seoTitle'); //根据key判断文件是否存在,如果不存在则)创建一个默认账户 $objLoginModel->createDefaultUserInfo(); $this->render('login', array('aryData' => $aryUserInfo)); }