Created
June 11, 2010 08:42
-
-
Save bzarzuela/434253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Secure Controllers | |
* | |
* @package Teleserv | |
* @author Bryan Zarzuela | |
*/ | |
class Teleserv_Controller_Action_Secure extends Zend_Controller_Action | |
{ | |
protected $_allowedRoles = array(); | |
protected $_user; | |
public function preDispatch() | |
{ | |
if (APPLICATION_ENV == 'testing'){ | |
// There's probably a toObject() function somewhere. Lol. | |
$data = json_decode(json_encode(array( | |
'username' => 'test', | |
'email' => 'test@teleserv.ph', | |
'first_name' => 'test', | |
'last_name' => 'user', | |
'nickname' => 'test', | |
'position' => 'test', | |
'employee_code' => 'test', | |
'roles' => array('superuser'), | |
))); | |
// Set the user to a fake superuser ident | |
$user = new Teleserv_Auth_Identity($data); | |
$this->_user = $user; | |
return; | |
} | |
if (APPLICATION_ENV == 'development'){ | |
if ( ! $this->_user) { | |
// There's probably a toObject() function somewhere. Lol. | |
$data = json_decode(json_encode(array( | |
'username' => 'bryan', | |
'email' => 'bryan@teleserv.ph', | |
'first_name' => 'Bryan', | |
'last_name' => 'Zarzuela', | |
'nickname' => 'bryan', | |
'position' => 'TTSSP', | |
'employee_code' => '07050200949', | |
'roles' => array('superuser'), | |
))); | |
// Set the user to a fake superuser ident | |
$user = new Teleserv_Auth_Identity($data); | |
$this->_user = $user; | |
return; | |
} | |
} | |
$sess = new Zend_Session_Namespace('auth'); | |
if (is_null($sess->user)) { | |
throw new Exception("Login Required"); | |
} | |
$user = $sess->user; | |
if ( ! $user->belongsTo($this->_allowedRoles)) { | |
throw new Exception("Access Denied"); | |
} | |
$this->_user = $user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment