Merge branch 'development' of http://git.westgis.ac.cn:8000/lijianxuan/westdc-core into development
This commit is contained in:
commit
8aa0abb88f
|
@ -15,6 +15,7 @@ class AuthenticationService
|
|||
protected $role;
|
||||
|
||||
public $loginRouterName = "login";
|
||||
public $logoutRouterName = "logout";
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
@ -45,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))
|
||||
|
@ -68,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())
|
||||
{
|
||||
|
@ -85,8 +88,38 @@ class AuthenticationService
|
|||
{
|
||||
$account = new Account();
|
||||
$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)
|
||||
|
|
|
@ -1,43 +1,37 @@
|
|||
<?php
|
||||
namespace Westdc\Db;
|
||||
|
||||
use Westdc\Service\AbstractServiceManager;
|
||||
use Zend\Db\Adapter\Adapter;
|
||||
use Zend\Config\Config as Zend_Config;
|
||||
|
||||
class Db extends AbstractServiceManager
|
||||
class Db
|
||||
{
|
||||
private $db;
|
||||
|
||||
function __construct(&$db = "",$param = array())
|
||||
{
|
||||
$configService = $this->getServiceManager()->get('Config');
|
||||
$config_local = $configService->get("local.php");
|
||||
|
||||
if(is_array($param) && count($param)>0)
|
||||
{
|
||||
$this->db = new Adapter($param);
|
||||
}else{
|
||||
$this->db = new Adapter(array(
|
||||
private static $_instance = NULL;
|
||||
|
||||
private function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance(){
|
||||
|
||||
if (self::$_instance === NULL) {
|
||||
|
||||
$config_local = new Zend_Config(include "config/autoload/local.php");
|
||||
|
||||
self::$_instance = new Adapter(array(
|
||||
'driver' => $config_local->db->driver,
|
||||
'hostname' => $config_local->db->hostname,
|
||||
'port' => $config_local->db->port,
|
||||
'port' => $config_local->db->port,
|
||||
'database' => $config_local->db->database,
|
||||
'username' => $config_local->db->username,
|
||||
'password' => $config_local->db->password
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
$db = $this->db;
|
||||
return self::$_instance;
|
||||
|
||||
}
|
||||
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function setConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,7 @@ class Dbh
|
|||
function __construct($db = NULL)
|
||||
{
|
||||
if($db == NULL)
|
||||
$this->db = new PDO();
|
||||
$this->db = PDO::getInstance();
|
||||
else
|
||||
$this->db = $db;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,33 @@
|
|||
<?php
|
||||
namespace Westdc\Db;
|
||||
|
||||
use Westdc\Helpers\Config;
|
||||
use Zend\Config\Config as Zend_Config;
|
||||
|
||||
class Pdo extends \PDO
|
||||
class Pdo
|
||||
{
|
||||
|
||||
private static $_instance = NULL;
|
||||
|
||||
function __construct($DSN = NULL)
|
||||
private function __construct($DSN = NULL)
|
||||
{
|
||||
if (!empty($DSN)) {
|
||||
parent::__construct($DSN);
|
||||
} else {
|
||||
$config_local = Config::get('local');
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
|
||||
if (self::$_instance === null) {
|
||||
$config_local = new Zend_Config(include "config/autoload/local.php");
|
||||
|
||||
$dsn = "pgsql:host={$config_local->db->hostname};"
|
||||
. "port={$config_local->db->port};"
|
||||
. "dbname={$config_local->db->database};"
|
||||
. "user={$config_local->db->username};"
|
||||
. "password={$config_local->db->password}";
|
||||
parent::__construct($dsn);
|
||||
self::$_instance = new \PDO($dsn);
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,8 @@ class Auth
|
|||
|
||||
public function clearIndentity()
|
||||
{
|
||||
return $this->auth->clearIdentity();
|
||||
$this->auth->clearIdentity();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getIdentity($field = "")
|
||||
|
|
|
@ -11,8 +11,6 @@ use Westdc\Helpers\Assist as view;
|
|||
use Westdc\Helpers\Config;
|
||||
use Westdc\Helpers\Dbh as dbh;
|
||||
use Westdc\Db\Db as Zend_Db;
|
||||
use Westdc\Mail\Mail;
|
||||
use Westdc\User\Member;
|
||||
|
||||
class Account extends AbstractEventManager implements ServiceManagerAwareInterface
|
||||
{
|
||||
|
@ -95,17 +93,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
$registerData = [
|
||||
'username' => $data['username'],
|
||||
'password' => md5($data['password']),
|
||||
'usertype' => 'guest',
|
||||
'usertype' => $this->RoleMember,
|
||||
'email' => $data['email'],
|
||||
'realname' => $data['realname'],
|
||||
'unit' => $data['unit'],
|
||||
'address' => $data['address'],
|
||||
'project' => $data['project'],
|
||||
'phone' => $data['phone'],
|
||||
'project_id' => $data['project_id'],
|
||||
'project_type' => $data['project_type'],
|
||||
'project_title' => $data['project_title'],
|
||||
'project_leader' => $data['project_leader'],
|
||||
];
|
||||
|
||||
$dbh = new dbh();
|
||||
|
@ -118,11 +107,10 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
|
||||
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]);
|
||||
}
|
||||
|
||||
$data = $registerData;
|
||||
$params = compact('data','id');
|
||||
$this->getEventManager()->trigger('register.success', $this, $params);
|
||||
return array("success" => 1);
|
||||
|
@ -161,8 +149,8 @@ class Account extends AbstractEventManager implements ServiceManagerAwareInterfa
|
|||
|
||||
if(isset($state['success']))
|
||||
{
|
||||
//$mb = new Member();
|
||||
//$mb->putcookie($data[$this->FieldUsername],$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'));
|
||||
|
|
|
@ -6,7 +6,7 @@ use Westdc\Db\Pdo as Db;
|
|||
|
||||
class Cookie
|
||||
{
|
||||
var $ck='Dxe8SqIcmyUf';
|
||||
var $ck='ff08XearZpUkjl3H';
|
||||
var $db; //传入PDO对象
|
||||
var $mid; //会员ID
|
||||
|
||||
|
@ -27,14 +27,14 @@ class Cookie
|
|||
|
||||
function __construct()
|
||||
{
|
||||
$this->db = new Db();
|
||||
$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)
|
||||
{
|
||||
|
|
|
@ -163,12 +163,23 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac
|
|||
* @return bool
|
||||
*/
|
||||
public function cancel($id){
|
||||
if(!is_numeric($id) || $id<1)
|
||||
return false;
|
||||
|
||||
$this->getEventManager()->trigger('review.canceled', $this, compact('id'));
|
||||
if(is_numeric($id))
|
||||
{
|
||||
$this->getEventManager()->trigger('review.canceled', $this, compact('id'));
|
||||
|
||||
return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED);
|
||||
return $this->changeStatus($id,self::REVIEW_STATUS_CANCELED);
|
||||
}elseif(is_array($id)){
|
||||
foreach($id as $item){
|
||||
$item = (int)$item;
|
||||
if($this->changeStatus($item,self::REVIEW_STATUS_CANCELED) === false)
|
||||
return "ID:$item:取消失败";
|
||||
}
|
||||
$this->getEventManager()->trigger('review.canceled', $this, compact('id'));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,8 +209,49 @@ class Review extends AbstractEventManager implements ServiceManagerAwareInterfac
|
|||
|
||||
}//accept($id)
|
||||
|
||||
/**
|
||||
* 重置评审,将评审的状态设置为投稿元数据状态
|
||||
* @param $id
|
||||
* @return array|bool
|
||||
*/
|
||||
public function reset($id){
|
||||
|
||||
if(!is_array($id))
|
||||
{
|
||||
if($this->getStatus($id) != self::REVIEW_STATUS_CANCELED)
|
||||
return [
|
||||
'此条评审的当前状态已经不属于被取消的评审,可能已经由其他管理人员重置',
|
||||
];
|
||||
|
||||
$status = $this->changeStatus($id,self::REVIEW_STATUS_DEFAULT);
|
||||
|
||||
if(false === $status)
|
||||
return false;
|
||||
|
||||
}else{
|
||||
$message = [];
|
||||
foreach($id as $item)
|
||||
{
|
||||
$item = (int)$item;
|
||||
if($this->getStatus($item) != self::REVIEW_STATUS_CANCELED){
|
||||
$message[] = "ID:$item:此条评审的当前状态已经不属于被取消的评审,可能已经由其他管理人员重置";
|
||||
continue;
|
||||
}
|
||||
|
||||
$status = $this->changeStatus($item,self::REVIEW_STATUS_DEFAULT);
|
||||
|
||||
if(false === $status)
|
||||
$message[] = "ID:$item:重置失败";
|
||||
}
|
||||
|
||||
if(count($message) > 0)
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
$this->getEventManager()->trigger('review.reset', $this, compact('id'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,15 +13,12 @@ use Westdc\Db as WestdcDb;
|
|||
class Db {
|
||||
|
||||
public function getZendDb(){
|
||||
|
||||
$dbObject = new WestdcDb\Db();
|
||||
|
||||
return $dbObject->getAdapter();
|
||||
return WestdcDb\Db::getInstance();
|
||||
}
|
||||
|
||||
public function getPdo()
|
||||
{
|
||||
return new WestdcDb\Pdo;
|
||||
return WestdcDb\Pdo::getInstance();
|
||||
}
|
||||
|
||||
public function getDbh()
|
||||
|
|
|
@ -34,7 +34,7 @@ class Account implements EventManagerAwareInterface
|
|||
|
||||
function __construct()
|
||||
{
|
||||
$this->db = new Db();
|
||||
$this->db = Db::getInstance();
|
||||
$this->config = Config::get();
|
||||
|
||||
$Listener = new Listener();
|
||||
|
@ -173,8 +173,8 @@ class Account implements EventManagerAwareInterface
|
|||
{
|
||||
$auth = new AuthenticationService();
|
||||
$auth->setStorage(new SessionStorage($this->config->session_namespace));
|
||||
|
||||
new Zend_Db($dbAdapter);
|
||||
|
||||
$dbAdapter = Zend_Db::getInstance();
|
||||
|
||||
$authAdapter = new \Zend\Authentication\Adapter\DbTable(
|
||||
$dbAdapter,
|
||||
|
|
|
@ -19,7 +19,7 @@ class LoginHandle
|
|||
|
||||
function __construct()
|
||||
{
|
||||
$this->db = new Db();
|
||||
$this->db = Db::getInstance();
|
||||
}
|
||||
|
||||
public function checkParam(EventInterface $e){
|
||||
|
|
|
@ -21,7 +21,7 @@ class RegisterHandle
|
|||
|
||||
function __construct($db = NULL)
|
||||
{
|
||||
$this->db = new Db();
|
||||
$this->db = Db::getInstance();
|
||||
$this->config = Config::get();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue