add new Westdc\Db\Db class (a extention for Zend_DB adapter),fixed errors

in Account module
This commit is contained in:
Jianxuan Li 2014-11-19 12:21:05 +08:00
parent f9dbc3e3db
commit 498d3c2f55
5 changed files with 77 additions and 11 deletions

View File

@ -87,6 +87,7 @@ class AuthenticationService
public function response($e) public function response($e)
{ {
//用户已经登录的情况 //用户已经登录的情况
if(view::User() !== false) if(view::User() !== false)
{ {
@ -99,6 +100,7 @@ class AuthenticationService
{ {
}else{ }else{
$response = $e->getResponse(); $response = $e->getResponse();
$response->setStatusCode(404); $response->setStatusCode(404);
$response->sendHeaders(); $response->sendHeaders();

42
Westdc/Db/Db.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace Westdc\Db;
use Westdc\Service\AbstractServiceManager;
use Zend\Db\Adapter\Adapter;
class Db extends AbstractServiceManager
{
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(
'driver' => $config_local->db->driver,
'hostname' => $config_local->db->hostname,
'database' => $config_local->db->database,
'username' => $config_local->db->username,
'password' => $config_local->db->password
));
}
$db = $this->db;
}
public function getAdapter()
{
return $this->db;
}
public function setConfig()
{
}
}

View File

@ -4,10 +4,12 @@ namespace Westdc\Member;
use Westdc\EventModel\AbstractEventManager; use Westdc\EventModel\AbstractEventManager;
use Zend\Authentication\AuthenticationService; use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage; use Zend\Authentication\Storage\Session as SessionStorage;
use Zend\Authentication\Adapter\DbTable;
use Westdc\Helpers\Assist as view; use Westdc\Helpers\Assist as view;
use Westdc\Helpers\Config; use Westdc\Helpers\Config;
use Westdc\Helpers\Dbh as dbh; use Westdc\Helpers\Dbh as dbh;
use Westdc\Db\PDO as Db; use Westdc\Db\Pdo as Db;
use Westdc\Db\Db as Zend_Db;
use Westdc\Mail\Mail; use Westdc\Mail\Mail;
use Westdc\User\Member; use Westdc\User\Member;
@ -145,28 +147,28 @@ class Account extends AbstractEventManager
new Zend_Db($dbAdapter); new Zend_Db($dbAdapter);
$authAdapter = new \Zend\Authentication\Adapter\DbTable( $authAdapter = new DbTable(
$dbAdapter, $dbAdapter,
$this->memberTable, 'users',
$this->FieldUsername, 'username',
$this->FieldPasword 'password'
); );
if($md5 === true) if($md5 === true)
{ {
$password = md5($data[$this->FieldPasword]); $password = md5($data['password']);
}else{ }else{
$password = $data[$this->FieldPasword]; $password = $data['password'];
} }
$authAdapter $authAdapter
->setIdentity($data[$this->FieldUsername]) ->setIdentity($data['username'])
->setCredential($password) ->setCredential($password)
; ;
$result = $authAdapter->authenticate(); $result = $authAdapter->authenticate();
$user = $authAdapter->getResultRowObject(null,array($this->FieldPasword)); $user = $authAdapter->getResultRowObject(null,array('password'));
if(!$result->isValid()) if(!$result->isValid())
{ {

View File

@ -44,7 +44,8 @@ class Config {
if($configFileExt == "php") if($configFileExt == "php")
{ {
return new Zend_Config(include_once($configFile)); $config_arr = include $configFile;
return new Zend_Config($config_arr);
} }
if($configFileExt == 'ini') if($configFileExt == 'ini')

View File

@ -0,0 +1,19 @@
<?php
namespace Westdc\Service\ServiceAgent;
class Gravatar{
function Get( $email, $size='' ) {
$default = "http://www.msgfm.com/static/img/gCons/agent.png";
if(empty($size))
{
$size = 40;
}
$url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
return $url;
}
}