/** * 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)); }
/** * Cancel bind */ public function actionCancelbind() { // Get key $os = DIRECTORY_SEPARATOR == '\\' ? "windows" : "linux"; $mac_addr = new CMac($os); $strRKEY = ''; if (file_exists(WEB_ROOT . '/js/RKEY.TXT')) { $strRKEY = file_get_contents(WEB_ROOT . '/js/RKEY.TXT'); } $boolResult = $this->generateRKEY(); if ($boolResult === true) { $boolResult = $this->actionGeneratekey(true); } // send cancel bind request UtilApi::callCancelbind(md5($mac_addr->mac_addr . '-' . $strRKEY)); if ($boolResult === true) { UtilMsg::saveTipToSession(CUtil::i18n('exception,bound_cancel_success')); } else { UtilMsg::saveErrorTipToSession(CUtil::i18n('exception,bound_cancel_faild')); } $this->redirect(array('index/index')); }