Initial Commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
class App_Service_Auth
|
||||
{
|
||||
protected $_auth;
|
||||
protected $_configs;
|
||||
protected $_acl;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->_configs = new App_Service_ConfigManager();
|
||||
$this->_acl = new App_Model_Acl_Acl();
|
||||
}
|
||||
|
||||
public function authenticate($credentials)
|
||||
{
|
||||
$adapter = $this->getAuthAdapter($credentials);
|
||||
$auth = $this->getAuth();
|
||||
$result = $auth->authenticate($adapter);
|
||||
|
||||
if (!$result->isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $adapter->getResultRowObject();
|
||||
Zend_Registry::set("username",$user->username);
|
||||
Zend_Registry::set("role",$user->role);
|
||||
|
||||
$auth->getStorage()->write($user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAuth()
|
||||
{
|
||||
if (null === $this->_auth) {
|
||||
$this->_auth = Zend_Auth::getInstance();
|
||||
}
|
||||
return $this->_auth;
|
||||
}
|
||||
|
||||
public function getIdentity()
|
||||
{
|
||||
$auth = $this->getAuth();
|
||||
if ($auth->hasIdentity()) {
|
||||
return $auth->getIdentity();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkPermission($resourceName){
|
||||
return $this->_acl->isAllowed($this->getIdentity()->role, $resourceName);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->getAuth()->clearIdentity();
|
||||
}
|
||||
|
||||
public function getAuthAdapter($values)
|
||||
{
|
||||
$salt = Zend_Registry::get('ENVIROMENTS')->get('password_salt');
|
||||
$authAdapter = new Zend_Auth_Adapter_DbTable(
|
||||
Zend_Db_Table_Abstract::getDefaultAdapter(),
|
||||
'users',
|
||||
'username',
|
||||
'password',
|
||||
"MD5(CONCAT('$salt',?))"
|
||||
);
|
||||
$authAdapter->setIdentity($values['username']);
|
||||
$authAdapter->setCredential($values['password']);
|
||||
return $authAdapter;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user