diff --git a/Westdc/Authentication/AuthenticationService.php b/Westdc/Authentication/AuthenticationService.php index 9bf780e..5058470 100644 --- a/Westdc/Authentication/AuthenticationService.php +++ b/Westdc/Authentication/AuthenticationService.php @@ -2,11 +2,9 @@ namespace Westdc\Authentication; use Zend\Permissions\Acl\Acl; -use Zend\Permissions\Acl\Role\GenericRole as Role; -use Zend\Permissions\Acl\Resource\GenericResource as Resource; use Westdc\Helpers\Assist as view; use Westdc\Member\Cookie; -use Zend\Mvc\MvcEvent; +use Westdc\User\Account; class AuthenticationService { @@ -17,6 +15,7 @@ class AuthenticationService protected $role; public $loginRouterName = "login"; + public $logoutRouterName = "logout"; function __construct() { @@ -47,9 +46,12 @@ class AuthenticationService return true; } -// view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); + //view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); - $this->preCookieCheck(); + if($rsp = $this->preCookieCheck($e) !== false) + { + return $rsp; + } try{ if(!$this->acl->hasResource($controller)) @@ -70,14 +72,13 @@ class AuthenticationService } } }catch (Exception $e) { - //echo 'Caught exception: ', $e->getMessage(), "\n"; $this->badRequest($e); return; } } - public function preCookieCheck() + public function preCookieCheck($e) { if(!view::User()) { @@ -86,9 +87,39 @@ class AuthenticationService if($mb->checkcookie()) { $account = new Account(); - $account->cookieLogin(array($mb->FieldUsername=>$mb->user,$mb->FieldPasword=>$mb->srpwd)); + $account->cookieLogin(array('username'=>$mb->user)); + + $response = $e->getResponse(); + $response->setStatusCode(200); + $response->sendHeaders(); + + $layout = $e->getViewModel(); + + $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager'); + $partial = $viewHelperManager->get('partial'); + + $page_content = $partial( + 'layout/layout/message', + array( + 'message' => '您的账号已自动登陆', + 'url'=> [ + ['title' => '立即跳转', 'url' => $_SERVER['REQUEST_URI']], + ['title'=>'退出登陆','url'=>$e->getRouter()->assemble(array(), array('name' => $this->logoutRouterName))] + ], + ) + ); + + $layout->setVariable('content',$page_content); + $layout->setTemplate('layout/layout'); + + $e->stopPropagation(); + + return $response; + } } + + return false; } public function response($e) diff --git a/Westdc/Db/Pdo.php b/Westdc/Db/Pdo.php index 4146ecc..8691867 100644 --- a/Westdc/Db/Pdo.php +++ b/Westdc/Db/Pdo.php @@ -1,7 +1,7 @@ getEventManager()->attachAggregate($Listener); - $configService = $this->serviceManager->get('ConfigService'); $this->config = $configService->get('file.php'); } @@ -51,6 +50,16 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac return $this->upload($files,$rootDir,$childDir,$fileName,$dateDirModel); } + /** + * 添加默认侦听器,会将信息保存到Attachments数据表 + */ + public function attachDefaultListener() + { + $Listener = new DefaultFileUploadListener; + $this->getEventManager()->attachAggregate($Listener); + $this->defaultListener = true; + } + /** * 上传文件 * @param $files 上传文件的信息 e.g.$_FILE['fileData'] @@ -73,11 +82,15 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $file = $files; $results = $this->getEventManager()->trigger('upload.pre', $this, compact('file')); - $cache_data = $results->last(); - if($cache_data !== true) + if($this->returnInPreCheckTrigger === true) { - return $cache_data; + $cache_data = $results->last(); + + if($cache_data !== true) + { + return $cache_data; + } } $fileService = $this->serviceManager->get('File'); @@ -88,7 +101,11 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac if($dateDirModel !== false) $this->makeDateDir($dateDirModel); - $this->setFileName($fileName , $fileService->getFileTextExt($files['name'])); + if(empty($this->fileName) || empty($fileName)) + $this->setFileName(NULL , $fileService->getFileTextExt($files['name'])); + + if(!empty($fileName)) + $this->setFileName($fileName , $fileService->getFileTextExt($files['name'])); //移动文件 $file_path = $this->getUploadPath() . $this->getFileName(); @@ -106,7 +123,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $file_data['file_ext'] = $fileService->getFileTextExt($files['name']); $file_data['file_mime'] = $fileService->getFileMime($file_path); - if(!empty($file_data) && is_array($file_data)) + if(!empty($this->params) && is_array($this->params)) { $file_data = array_merge($file_data,$this->params); } @@ -203,26 +220,52 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac * @param $fileName * @param $fileExt */ - public function setFileName($fileName,$fileExt) + public function setFileName($fileName,$fileExt = "") { if(!empty($fileName)){ - $this->fileName = $fileName . "." .$fileExt; + + if(empty($fileExt)) + { + $fileExt = pathinfo($fileName,PATHINFO_EXTENSION); + } + + if(empty($fileExt)) + $this->fileName = $fileName; + else + $this->fileName = $fileName . "." .$fileExt; + return; } $tools = $this->serviceManager->get('Tools'); $uuid = $tools->uuid(); - $this->fileName = $uuid . "." . $fileExt; + if(empty($fileExt)) + $this->fileName = $uuid; + else + $this->fileName = $uuid . "." . $fileExt; + return; } + /** + * @param $params + */ public function setParams($params) { $this->params = $params; } + /** + * 强制关闭文件上传前的钩子,默认是所有上传必须执行此钩子已避免上传文件不符合规格 + * 除了后台中特殊的文件操作之外不建议关闭 + */ + public function forceDetachPreCheckTrigger() + { + $this->returnInPreCheckTrigger = false; + } + /** * @return string */ diff --git a/Westdc/Helpers/Auth.php b/Westdc/Helpers/Auth.php index 5334bc1..c12b762 100644 --- a/Westdc/Helpers/Auth.php +++ b/Westdc/Helpers/Auth.php @@ -1,13 +1,13 @@ auth->clearIdentity(); + $this->auth->clearIdentity(); + return true; } - public function getIdentity($field) + public function getIdentity($field = "") { + if(empty($field)) + return $this->auth->getIdentity(); + if(isset($this->auth->getIdentity()->$field)) return $this->auth->getIdentity()->$field; else return null; } + + public function write($user) + { + + if(is_array($user)) + $user = (object)$user; + + $this->auth->getStorage()->write($user); + } } \ No newline at end of file diff --git a/Westdc/Helpers/Config.php b/Westdc/Helpers/Config.php index 91e5072..b26091c 100644 --- a/Westdc/Helpers/Config.php +++ b/Westdc/Helpers/Config.php @@ -3,26 +3,43 @@ namespace Westdc\Helpers; class Config { - private $config_path = array( - 'local' => "config/autoload/local.php", - 'global' => "config/autoload/global.php" - ); - + function __construct() { //$reader = new \Zend\Config\Reader\Ini(); //$data = $reader->fromFile('config/config.ini'); } - static function get($type = 'global') + static function get($configName = 'global') { - $config_path = array( - 'local' => "config/autoload/local.php", - 'global' => "config/autoload/global.php", - 'file' => "config/autoload/file.php" + if(defined(CONFIG_PATH)) + { + throw new \RuntimeException('Not found the config files path'); + } + + $config_path = CONFIG_PATH; + + if(empty($configName)) + $configName = "global.php"; + + if(!preg_match("/(\\/|\\\)$/",$config_path)) + { + $config_path .= "/"; + } + + $config_names = array( + 'local' => "local.php", + 'global' => "global.php", + 'file' => "file.php" ); + + $configFile = $config_path .'autoload/' . $config_names[$configName]; + + unset($config_path); + unset($configName); - $config = new \Zend\Config\Config(include $config_path[$type]); + $config = new \Zend\Config\Config(include $configFile); + return $config; } diff --git a/Westdc/Helpers/Layout.php b/Westdc/Helpers/Layout.php index 136c77a..44ce42a 100644 --- a/Westdc/Helpers/Layout.php +++ b/Westdc/Helpers/Layout.php @@ -3,17 +3,15 @@ namespace Westdc\Helpers; use \Zend\Authentication\AuthenticationService; use \Zend\Authentication\Storage\Session as SessionStorage; -use \Westdc\Helpers\Config; -use Westdc\Helpers\MobileDetect; use View as view; class Layout { - public $config; + function __construct() { - $this->config = Config::get(); + } //设置网页标题 @@ -26,8 +24,8 @@ class Layout return; } - $action = $matches->getParam('action'); - $controller = $matches->getParam('controller'); +// $action = $matches->getParam('action'); +// $controller = $matches->getParam('controller'); $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager'); @@ -36,15 +34,7 @@ class Layout // Setting a separator string for segments $headTitleHelper->setSeparator(' - '); - if(isset($this->config->title_map->$controller->action->$action)) - { - $headTitleHelper->append($this->config->title_map->$controller->action->$action->title); - } - - if(isset($this->config->title_map->$controller)) - { - $headTitleHelper->append($this->config->title_map->$controller->title); - } + return; } //导航条按钮激活 diff --git a/Westdc/Helpers/Paginator.php b/Westdc/Helpers/Paginator.php index 2519f00..4aadcdf 100644 --- a/Westdc/Helpers/Paginator.php +++ b/Westdc/Helpers/Paginator.php @@ -30,10 +30,6 @@ class Paginator implements ServiceManagerAwareInterface{ { $this->serviceManager = $serviceManager; - $this->setPageLimit(); - $this->setPageRange(); - $this->setRoute(); - return $this; } @@ -97,6 +93,16 @@ class Paginator implements ServiceManagerAwareInterface{ { $page = $ctl->params()->fromRoute('page'); + if(empty($this->pageLimit)) + $this->setPageLimit(); + + if(empty($this->pageRange)) + $this->setPageRange(); + + if(empty($this->route)) + $this->setRoute(); + + if(is_array($data)) $data = new ArrayAdapter($data); diff --git a/Westdc/Helpers/Tools.php b/Westdc/Helpers/Tools.php index ee0658f..d8e4d3d 100644 --- a/Westdc/Helpers/Tools.php +++ b/Westdc/Helpers/Tools.php @@ -45,8 +45,12 @@ class Tools { { $response = array(); $handle = popen("$cmd 2>&1", 'r'); - $read = ''; + while ($read = fread($handle, 20096)) { + + if(!mb_detect_encoding($read, 'UTF-8', true)) + iconv("GB2312","UTF-8",$read); + $response[] = trim($read); } pclose($handle); diff --git a/Westdc/Mail/Sender.php b/Westdc/Mail/Sender.php index b7c860c..51dbc9b 100644 --- a/Westdc/Mail/Sender.php +++ b/Westdc/Mail/Sender.php @@ -10,6 +10,7 @@ namespace Westdc\Mail; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; +use Westdc\Service\ServiceManager as WestdcServiceManager; class Sender implements ServiceManagerAwareInterface{ @@ -24,6 +25,15 @@ class Sender implements ServiceManagerAwareInterface{ return $this; } + public function __construct() + { + if(!$this->serviceManager instanceof ServiceManager) + { + $serviceManager = new WestdcServiceManager(); + $this->serviceManager = $serviceManager->getServiceManager(); + } + } + /** * 发送即时邮件 * @param $options diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index 43da9fe..5dfedd5 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -10,11 +10,7 @@ use Zend\Authentication\Adapter\DbTable; use Westdc\Helpers\Assist as view; use Westdc\Helpers\Config; use Westdc\Helpers\Dbh as dbh; -use Westdc\Db\Pdo as Db; use Westdc\Db\Db as Zend_Db; -use Westdc\Mail\Mail; -use Westdc\User\Member; - class Account extends AbstractEventManager implements ServiceManagerAwareInterface { @@ -64,11 +60,15 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa return $rs->fetch(); } - //注册 + /** + * 用户注册 + * @param $data + * @return array + */ public function register($data) { $params = compact('data'); - $results = $this->getEventManager()->trigger('register.checkParam', $this, $params); + $results = $this->getEventManager()->trigger('register.pre', $this, $params); $cache_data = $results->last(); if($cache_data !== true) @@ -80,43 +80,39 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa return $cache_data; } } - - $results = $this->getEventManager()->trigger('register.checkUser', $this, $params); - $cache_data = $results->last(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - + + /** + * 将数据分为两组,一组用于做注册成功后的登陆,一组用于写入数据库 + * 写入数据库的数据需要完全重建一个新的,防止因为前端传入时有人恶意增加字段造成破坏 + */ $loginData = array( 'username'=>$data['username'], 'password'=>$data['password'] ); - - $data['password'] = md5($data['password']); - $data['usertype'] = "guest"; - unset($data['confirm_password']); + + $registerData = [ + 'username' => $data['username'], + 'password' => md5($data['password']), + 'usertype' => $this->RoleMember, + 'email' => $data['email'], + ]; $dbh = new dbh(); - $id = $dbh->insert($this->memberTable,$data,true); + $id = $dbh->insert($this->memberTable,$registerData,true); if(!empty($id) && is_numeric($id)) { $this->storeLogin($loginData); + if(isset($state['success'])) { - //$mb = new Member(); - //$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); } + $params = compact('data','id'); - $results = $this->getEventManager()->trigger('register.success', $this, $params); + $this->getEventManager()->trigger('register.success', $this, $params); return array("success" => 1); }else{ if($id === false) @@ -128,11 +124,15 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa } }//register - - //登陆 + + /** + * 用户登陆 + * @param $data + * @return array + */ public function login($data) { - $results = $this->getEventManager()->trigger('login.checkParam', $this, compact('data')); + $results = $this->getEventManager()->trigger('login.pre', $this, compact('data')); $cache_data = $results->last(); if($cache_data !== true) @@ -149,14 +149,25 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa if(isset($state['success'])) { - //$mb = new Member(); - //$mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); - } + $mb = new Cookie(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); + + $user = (array)$state['user']; + $this->getEventManager()->trigger('login.success', $this, compact('user')); + }else{ + $this->getEventManager()->trigger('login.failed', $this, compact('data')); + } - return $state; + return $state; }//login - - //storeLogin + + /** + * 存储用户登陆信息 + * 为了防止login中的用户信息检查不规范,再加入一层内置的数据库权限检查,以防通过漏洞登入系统 + * @param $data + * @param bool $md5 是否对密码进行md5加密再校验 + * @return array + */ private function storeLogin($data,$md5 = true) { $auth = new AuthenticationService(); @@ -184,24 +195,20 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa ; $result = $authAdapter->authenticate(); - - $user = $authAdapter->getResultRowObject(null,array('password')); - + if(!$result->isValid()) { return array("error"=>"用户信息验证失败"); } - - $email = $user->email; - $results = $this->getEventManager()->trigger('login.success.createAvatar', $this, compact('email')); - $user->avatar = $results->last(); - $auth->getStorage()->write($user); - - $id = $user->id; - $results = $this->getEventManager()->trigger('login.success.updateStatus', $this, compact('id')); + + $user = $authAdapter->getResultRowObject(null,array('password')); + $auth->getStorage()->write($user); - return array('success'=>1); - } + return array( + 'success'=>1, + 'user' => $user + ); + }//storeLogin public function cookieLogin($data) { diff --git a/Westdc/Member/Cookie.php b/Westdc/Member/Cookie.php index 4d56afd..2b29036 100644 --- a/Westdc/Member/Cookie.php +++ b/Westdc/Member/Cookie.php @@ -6,7 +6,7 @@ use Westdc\Db\Pdo as Db; class Cookie { - var $ck='Dxe8SqIcmyUf'; + var $ck='ff08XearZpUkjl3H'; var $db; //传入PDO对象 var $mid; //会员ID @@ -29,12 +29,12 @@ class Cookie { $this->db = Db::getInstance(); $this->config = Config::get(); - - if(!empty($_COOKIE['scr'])) + + if(isset($_COOKIE['scr']) && !empty($_COOKIE['scr'])) { $this->scr = $_COOKIE['scr']; } - if(!empty($_COOKIE['user'])) + if(isset($_COOKIE['user']) && !empty($_COOKIE['user'])) { $this->user= $_COOKIE['user']; } @@ -48,7 +48,7 @@ class Cookie { $uname = $this->user; $hash = $this->scr; - + if(!empty($uname) && !empty($hash)) { if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash)) @@ -61,7 +61,7 @@ class Cookie $rs = $this->db->query($sql); $row = $rs->fetch(); $scr = $this->makescr($row['userid'],$row['pwd']); - + if($hash == $scr) { $this->srpwd=$row['pwd']; @@ -75,26 +75,27 @@ class Cookie return false; }//exit }//function checkcookie - - /** - * putcookie - * - * 登陆成功后放置cookie,包含安全码 - * - * @param String $uname - * @param String $pwd - * @param Int $time - */ + + /** + * putcookie + * + * 登陆成功后放置cookie,包含安全码 + * + * @param $uname + * @param $pwd + * @param int $time + * @return bool + */ public function putcookie($uname,$pwd,$time = 604800) { try { - $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。 - + $scrString = $this->makescr($uname,md5($pwd));//加密验证串:防止用户密码被盗;防止伪造cookie。 + if(!is_numeric($time)) { $time = 604800; } - + setcookie('user',$uname,time()+$time,'/'); setcookie('scr',$scrString,time()+$time,'/'); @@ -110,6 +111,7 @@ class Cookie * * @param String $u * @param String $p + * @return string */ public function makescr($u,$p) { diff --git a/Westdc/Reference/Reference.php b/Westdc/Reference/Reference.php index e126cd0..699739b 100644 --- a/Westdc/Reference/Reference.php +++ b/Westdc/Reference/Reference.php @@ -97,6 +97,7 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter $appConfig = $configService->get('application.ini'); $fileUploadService = $this->serviceManager->get('File/Upload'); + $fileUploadService->attachDefaultListener(); $fileUploadService->setParams(['file_type' => 'literature']); $file_info = $fileUploadService($file,$appConfig['reference_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y); diff --git a/Westdc/Review/Review.php b/Westdc/Review/Review.php index 010988e..99362ea 100644 --- a/Westdc/Review/Review.php +++ b/Westdc/Review/Review.php @@ -10,6 +10,7 @@ namespace Westdc\Review; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; use Westdc\EventModel\AbstractEventManager; +use Zend\Db\Sql\Select; class Review extends AbstractEventManager implements ServiceManagerAwareInterface{ @@ -119,14 +120,43 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac RIGHT JOIN metadata md ON md.uuid=m.uuid LEFT JOIN users u ON u.id=m.userid LEFT JOIN geonetworkmetadata gn ON m.uuid=gn.uuid - WHERE m.status=0 $searchJoin + WHERE m.status=".self::REVIEW_STATUS_DEFAULT." $searchJoin {$this->orderSql} {$this->sortSql} {$this->limitSql}"; $rs = $this->db->query($sql); - return $rs->fetchAll(); + return $rs->fetchAll(\PDO::FETCH_ASSOC); }//getDraft() + /** + * 获取被取消评审的元数据 + * @return mixed + */ + public function getCanceled() + { + $this->processOptions(); + + $searchJoin = ""; + if(isset($this->opt->keyword) && !empty($this->opt->keyword)) + { + $searchJoin = " AND md.title LIKE '%{$this->opt->keyword}%'"; + } + + if(empty($this->orderSql)) + { + $this->orderSql = "ORDER BY m.ts_created DESC"; + } + + $sql = "SELECT m.id,md.title,md.uuid,m.status,m.ts_created FROM mdstatus m + RIGHT JOIN metadata md ON md.uuid=m.uuid + WHERE m.status=".self::REVIEW_STATUS_CANCELED." $searchJoin + {$this->orderSql} {$this->sortSql} + {$this->limitSql}"; + + $rs = $this->db->query($sql); + return $rs->fetchAll(\PDO::FETCH_ASSOC); + } + /** * 取消评审 * @param $id @@ -135,6 +165,9 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac public function cancel($id){ if(!is_numeric($id) || $id<1) return false; + + $this->getEventManager()->trigger('review.canceled', $this, compact('id')); + return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED); } @@ -159,43 +192,12 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac return false; } - $authorEmail = $this->getAuthor($id); - - foreach($authorEmail as $v) - { - $mailSender = $this->serviceManager->get('Mail/Sender'); - $mailSender->backend([ - 'email' => $v['email'], - 'name' => !empty($v['realname']) ? $v['realname']:$v['username'], - 'template' => 'review-new-accept', - 'data' => [ - 'uuid' => $v['uuid'], - 'title' => $v['title'], - ] - ]); - } + $this->getEventManager()->trigger('review.accepted', $this, compact('id')); return true; }//accept($id) - /** - * 获得某条评审涉及的元数据相关作者信息(email,元数据标题,uuid) - * @param $id - * @return mixed - */ - public function getAuthor($id){ - $sql = "SELECT DISTINCT u.email,u.realname,u.username,m.title,m.uuid FROM mdstatus s - LEFT JOIN metadata m ON s.uuid=m.uuid - RIGHT JOIN mdauthor a ON s.uuid=a.uuid - LEFT JOIN users u ON a.userid=u.id - WHERE s.id=$id - ORDER BY u.email"; - - $rs = $this->db->query($sql); - return $rs->fetchAll(\PDO::FETCH_ASSOC); - } - public function reset($id){ } diff --git a/Westdc/Service/ServiceAgent/Account.php b/Westdc/Service/ServiceAgent/Account.php deleted file mode 100644 index b35cee4..0000000 --- a/Westdc/Service/ServiceAgent/Account.php +++ /dev/null @@ -1,17 +0,0 @@ -getAdapter(); } diff --git a/Westdc/User/Account.php b/Westdc/User/Account.php index 9c526ff..a8143f0 100644 --- a/Westdc/User/Account.php +++ b/Westdc/User/Account.php @@ -8,9 +8,9 @@ use Zend\Authentication\AuthenticationService; use Zend\Authentication\Storage\Session as SessionStorage; use Westdc\Helpers\View as view; use Westdc\Helpers\Config; -use Westdc\Helpers\Dbh as dbh; -use Westdc\Helpers\PDO as Db; -use Westdc\Helpers\Db as Zend_Db; +use Westdc\Db\Dbh as dbh; +use Westdc\Db\Pdo as Db; +use Westdc\Db\Db as Zend_Db; use Westdc\Mail\Mail; use Westdc\User\Listener\AccountListener as Listener; use Westdc\User\Listener\PwdListener; @@ -18,7 +18,7 @@ use Westdc\User\Member; class Account implements EventManagerAwareInterface { - public $memberTable = "tbl_member"; + public $memberTable = "users"; public $FieldUsername = "username"; public $FieldPasword = "password"; public $FieldLastlogin = "ts_last_login"; @@ -60,16 +60,21 @@ class Account implements EventManagerAwareInterface } //获取账号信息,数组 - public function getAccountInfo($id = 0) - { - if($id == 0) - { - $id = view::User('id'); - } - $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } + public function getAccountInfo($id = 0) + { + + if(is_string($id)) + $sql = "SELECT * FROM ".$this->memberTable." WHERE username='$id'"; + elseif(is_numeric($id)) + { + if($id == 0) + $id == view::User('id'); + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; + } + + $rs = $this->db->query($sql); + return $rs->fetch(\PDO::FETCH_ASSOC); + } //注册 public function register($data) @@ -212,7 +217,14 @@ class Account implements EventManagerAwareInterface public function cookieLogin($data) { - return $this->storeLogin($data,false); + $data = $this->getAccountInfo($data['username']); + + if(!$data) + { + return false; + } + + return $this->storeLogin($data,false); } //注册信息参数 diff --git a/Westdc/User/Event/EditEvent.php b/Westdc/User/Event/EditEvent.php deleted file mode 100644 index 2bdcdc1..0000000 --- a/Westdc/User/Event/EditEvent.php +++ /dev/null @@ -1,13 +0,0 @@ -FieldPasword},status FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?"; $sth = $this->db->prepare($sql); $rs = $sth->execute(array($data[$this->FieldUsername])); - $row = $sth->fetch(); + $row = $sth->fetch(\PDO::FETCH_ASSOC); if(isset($row['id']) && !empty($row['id'])) { diff --git a/Westdc/User/Handle/PwdHandle.php b/Westdc/User/Handle/PwdHandle.php index a4058f2..8e741d1 100644 --- a/Westdc/User/Handle/PwdHandle.php +++ b/Westdc/User/Handle/PwdHandle.php @@ -1,12 +1,10 @@