Initial Commit

This commit is contained in:
GiacomoHome
2021-09-17 12:41:45 +02:00
commit 9001e4656e
570 changed files with 31013 additions and 0 deletions
+74
View File
@@ -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;
}
}