From 27beb8fbaf26b3d60c2460f9bc3975ba201df6ac Mon Sep 17 00:00:00 2001 From: cuixin Date: Fri, 19 Dec 2014 11:58:47 +0800 Subject: [PATCH] add user module --- .../Authentication/AuthenticationService.php | 2 +- Westdc/Helpers/Assist.php | 11 +- Westdc/Service/ServiceAgent/User.php | 17 +++ Westdc/User/Cookie.php | 135 ------------------ Westdc/User/Member.php | 135 ------------------ Westdc/User/Status.php | 54 +++++++ Westdc/User/User.php | 8 ++ Westdc/User/UserService.php | 32 ----- 8 files changed, 89 insertions(+), 305 deletions(-) create mode 100644 Westdc/Service/ServiceAgent/User.php delete mode 100644 Westdc/User/Cookie.php delete mode 100644 Westdc/User/Member.php create mode 100644 Westdc/User/Status.php delete mode 100644 Westdc/User/UserService.php diff --git a/Westdc/Authentication/AuthenticationService.php b/Westdc/Authentication/AuthenticationService.php index 2a14d8b..9818577 100644 --- a/Westdc/Authentication/AuthenticationService.php +++ b/Westdc/Authentication/AuthenticationService.php @@ -42,7 +42,7 @@ class AuthenticationService $controller = $e->getRouteMatch()->getParam('controller'); $action = $e->getRouteMatch()->getParam('action'); - //view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); +// view::Dump($e->getRouteMatch()->getMatchedRouteName() . ":" . $controller."-".$action,false); $this->preCookieCheck(); diff --git a/Westdc/Helpers/Assist.php b/Westdc/Helpers/Assist.php index 2884d9f..cab69e7 100644 --- a/Westdc/Helpers/Assist.php +++ b/Westdc/Helpers/Assist.php @@ -18,8 +18,15 @@ class Assist { $request = $ctl->getRequest(); $page = $ctl->params()->fromRoute('page'); - - $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($data)); + + if(is_array($data)){ + $data = new \Zend\Paginator\Adapter\ArrayAdapter($data); + } +// elseif($data instanceof ){ +// +// } + + $paginator = new \Zend\Paginator\Paginator($data); $paginator->setCurrentPageNumber($page) ->setItemCountPerPage($limit) ->setPageRange(6); diff --git a/Westdc/Service/ServiceAgent/User.php b/Westdc/Service/ServiceAgent/User.php new file mode 100644 index 0000000..78b4f0f --- /dev/null +++ b/Westdc/Service/ServiceAgent/User.php @@ -0,0 +1,17 @@ +db = new Db(); - $this->config = Config::get(); - - if(!empty($_COOKIE['scr'])) - { - $this->scr = $_COOKIE['scr']; - } - if(!empty($_COOKIE['user'])) - { - $this->user= $_COOKIE['user']; - } - } - - - /** - * 检测cookie - */ - public function checkcookie() - { - $uname = $this->user; - $hash = $this->scr; - - if(!empty($uname) && !empty($hash)) - { - if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash)) - { - $this->mid=0; - return false; - } - else{ - $sql = "select {$this->FieldUsername} as userid,{$this->FieldPasword} as pwd from {$this->memberTable} where {$this->FieldUsername}='$uname'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - $scr = $this->makescr($row['userid'],$row['pwd']); - - if($hash == $scr) - { - $this->srpwd=$row['pwd']; - return true; - } - else { - return false; - } - }//cookie安全 - }else { - return false; - }//exit - }//function checkcookie - - /** - * putcookie - * - * 登陆成功后放置cookie,包含安全码 - * - * @param String $uname - * @param String $pwd - * @param Int $time - */ - public function putcookie($uname,$pwd,$time = 604800) - { - try { - $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。 - - if(!is_numeric($time)) - { - $time = 604800; - } - - setcookie('user',$uname,time()+$time,'/'); - setcookie('scr',$scrString,time()+$time,'/'); - - return true; - } catch (Exception $e) { - return false; - } - - }//function putcookie - - /** - * 生成安全码 - * - * @param String $u - * @param String $p - */ - public function makescr($u,$p) - { - return substr(md5($u.$p.$this->ck),3,20); - } - - /** - * 清除cookie - */ - static function flushcookie() - { - setcookie('user','',time()-99999,'/'); - setcookie('scr','',time()-99999,'/'); - } - - public function getUser() - { - $sql = "SELECT * FROM ".$this->memberTable." m ORDER BY m.id DESC"; - $rs = $this->db->query($sql); - return $rs->fetchAll(); - } - -} \ No newline at end of file diff --git a/Westdc/User/Member.php b/Westdc/User/Member.php deleted file mode 100644 index 9666e98..0000000 --- a/Westdc/User/Member.php +++ /dev/null @@ -1,135 +0,0 @@ -db = new Db(); - $this->config = Config::get(); - - if(!empty($_COOKIE['scr'])) - { - $this->scr = $_COOKIE['scr']; - } - if(!empty($_COOKIE['user'])) - { - $this->user= $_COOKIE['user']; - } - } - - - /** - * 检测cookie - */ - public function checkcookie() - { - $uname = $this->user; - $hash = $this->scr; - - if(!empty($uname) && !empty($hash)) - { - if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash)) - { - $this->mid=0; - return false; - } - else{ - $sql = "select {$this->FieldUsername} as userid,{$this->FieldPasword} as pwd from {$this->memberTable} where {$this->FieldUsername}='$uname'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - $scr = $this->makescr($row['userid'],$row['pwd']); - - if($hash == $scr) - { - $this->srpwd=$row['pwd']; - return true; - } - else { - return false; - } - }//cookie安全 - }else { - return false; - }//exit - }//function checkcookie - - /** - * putcookie - * - * 登陆成功后放置cookie,包含安全码 - * - * @param String $uname - * @param String $pwd - * @param Int $time - */ - public function putcookie($uname,$pwd,$time = 604800) - { - try { - $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。 - - if(!is_numeric($time)) - { - $time = 604800; - } - - setcookie('user',$uname,time()+$time,'/'); - setcookie('scr',$scrString,time()+$time,'/'); - - return true; - } catch (Exception $e) { - return false; - } - - }//function putcookie - - /** - * 生成安全码 - * - * @param String $u - * @param String $p - */ - public function makescr($u,$p) - { - return substr(md5($u.$p.$this->ck),3,20); - } - - /** - * 清除cookie - */ - static function flushcookie() - { - setcookie('user','',time()-99999,'/'); - setcookie('scr','',time()-99999,'/'); - } - - public function getUser() - { - $sql = "SELECT * FROM ".$this->memberTable." m ORDER BY m.id DESC"; - $rs = $this->db->query($sql); - return $rs->fetchAll(); - } - -} \ No newline at end of file diff --git a/Westdc/User/Status.php b/Westdc/User/Status.php new file mode 100644 index 0000000..d19105a --- /dev/null +++ b/Westdc/User/Status.php @@ -0,0 +1,54 @@ +serviceManager = $serviceManager; + + $this->init(); + + return $this; + } + + private function init() + { + $dbService = $this->serviceManager->get('Db'); + $this->db = $dbService->getPdo(); + } + + + public function getUserCount(){ + + $sql="select count(id) as total from users"; + $uq=$this->db->query($sql); + + return $uq->fetchColumn(0); + + } + + public function getAdminCount(){ + + $sql="select count(id) as total from users where usertype='administrator'"; + $uq=$this->db->query($sql); + + return $uq->fetchColumn(0); + + } + +} \ No newline at end of file diff --git a/Westdc/User/User.php b/Westdc/User/User.php index b76aeb0..9fe7d49 100644 --- a/Westdc/User/User.php +++ b/Westdc/User/User.php @@ -33,6 +33,14 @@ class User extends AbstractEventManager implements ServiceManagerAwareInterface{ $this->db = $dbService->getPdo(); } + public function fetchAll(){ + $sql = "select * from users where usertype = 'member'"; + $rs = $this->db->query($sql); + return $rs->fetchAll(\PDO::FETCH_ASSOC); + + + } + } \ No newline at end of file diff --git a/Westdc/User/UserService.php b/Westdc/User/UserService.php deleted file mode 100644 index ef7a597..0000000 --- a/Westdc/User/UserService.php +++ /dev/null @@ -1,32 +0,0 @@ -serviceManager = $serviceManager; - - return $this; - } - -} \ No newline at end of file