add user module
This commit is contained in:
parent
a09322d720
commit
27beb8fbaf
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/4
|
||||
* Time: 11:23
|
||||
*/
|
||||
|
||||
namespace Westdc\Service\ServiceAgent;
|
||||
|
||||
use Westdc\User\User as Westdc_User;
|
||||
|
||||
class User extends Westdc_User
|
||||
{
|
||||
|
||||
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
namespace Westdc\User;
|
||||
|
||||
use Westdc\Helpers\Config;
|
||||
use Westdc\Db\PDO as Db;
|
||||
|
||||
class Cookie
|
||||
{
|
||||
var $ck='Dxe8SqIcmyUf';
|
||||
var $db; //传入PDO对象
|
||||
var $mid; //会员ID
|
||||
|
||||
public $scr; //cookie 安全码 $_COOKIE['scr']
|
||||
public $user;//cookie User $_COOKIE['user']
|
||||
|
||||
public $srpwd;//执行checkcookie后方可调用
|
||||
|
||||
public $memberTable = "users";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
public $FieldEmail = "email";
|
||||
public $FieldLastloginIp = "last_login_ip";
|
||||
public $GravatarEmailField = "gravatar_email";
|
||||
|
||||
public $RoleMember = "member";
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
namespace Sookon\User;
|
||||
|
||||
use Sookon\Helpers\Config;
|
||||
use Sookon\Helpers\PDO as Db;
|
||||
|
||||
class Member
|
||||
{
|
||||
var $ck='Dxe8SqIcmyUf';
|
||||
var $db; //传入PDO对象
|
||||
var $mid; //会员ID
|
||||
|
||||
public $scr; //cookie 安全码 $_COOKIE['scr']
|
||||
public $user;//cookie User $_COOKIE['user']
|
||||
|
||||
public $srpwd;//执行checkcookie后方可调用
|
||||
|
||||
public $memberTable = "tbl_member";
|
||||
public $FieldUsername = "username";
|
||||
public $FieldPasword = "password";
|
||||
public $FieldLastlogin = "ts_last_login";
|
||||
public $FieldEmail = "email";
|
||||
public $FieldLastloginIp = "last_login_ip";
|
||||
public $GravatarEmailField = "gravatar_email";
|
||||
|
||||
public $RoleMember = "member";
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Li Jianxuan
|
||||
* Date: 14-9-19
|
||||
* Time: 下午3:21
|
||||
*/
|
||||
|
||||
namespace Westdc\User;
|
||||
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
||||
|
||||
class Status implements ServiceManagerAwareInterface{
|
||||
|
||||
protected $serviceManager;
|
||||
|
||||
private $db;
|
||||
|
||||
public function setServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
$this->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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Li Jianxuan
|
||||
* Date: 14-9-19
|
||||
* Time: 下午4:23
|
||||
*/
|
||||
|
||||
namespace Westdc\User;
|
||||
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
||||
|
||||
class UserService implements ServiceManagerAwareInterface{
|
||||
|
||||
/**
|
||||
* @var ServiceManager
|
||||
*/
|
||||
protected $serviceManager;
|
||||
|
||||
/**
|
||||
* @param ServiceManager $serviceManager
|
||||
* @return service
|
||||
*/
|
||||
public function setServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
$this->serviceManager = $serviceManager;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue