Skip to content

Instantly share code, notes, and snippets.

@bzarzuela
Created June 11, 2010 08:42
Show Gist options
  • Save bzarzuela/434253 to your computer and use it in GitHub Desktop.
Save bzarzuela/434253 to your computer and use it in GitHub Desktop.
<?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