本文整理汇总了PHP中Zend_Auth::getIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Auth::getIdentity方法的具体用法?PHP Zend_Auth::getIdentity怎么用?PHP Zend_Auth::getIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Auth
的用法示例。
在下文中一共展示了Zend_Auth::getIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preDispatch
/**
* Hook into action controller preDispatch() workflow
*
* @return void
*/
public function preDispatch()
{
$role = Zend_Registry::get('config')->acl->defaultRole;
if ($this->_auth->hasIdentity()) {
$user = $this->_auth->getIdentity();
if (is_object($user) && !empty($user->role)) {
$role = $user->role;
}
}
$request = $this->_action->getRequest();
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
$this->_controllerName = $controller;
$resource = $controller;
$privilege = $action;
if (!$this->_acl->has($resource)) {
$resource = null;
}
if ($resource == 'error' && $privilege == 'error') {
return;
}
if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
$request->setModuleName('default')->setControllerName('auth')->setActionName('noaccess');
$request->setDispatched(false);
return;
}
}
示例2: _isAuthorized
protected function _isAuthorized($resource, $action)
{
$user = $this->_auth->hasIdentity() ? $this->_auth->getIdentity() : 'guest';
if (!$this->_acl->has($resource) || !$this->_acl->isAllowed($user, $resource, $action)) {
return false;
}
return true;
}
示例3: getPerson
/** Get the person's identity
* @access public
* @return boolean
*/
public function getPerson()
{
if ($this->_auth->hasIdentity()) {
return $this->_auth->getIdentity();
} else {
return false;
}
}
示例4: _isAuthorized
protected function _isAuthorized($controller, $action)
{
$this->_acl = Zend_Registry::get('acl');
$user = $this->_auth->getIdentity();
if (!$this->_acl->has($controller) || !$this->_acl->isAllowed($user, $controller, $action)) {
return false;
}
return true;
}
示例5: getRole
/** Get the user's role
* @access public
* @return string
*/
public function getRole()
{
if ($this->_auth->hasIdentity()) {
$user = $this->_auth->getIdentity();
$role = $user->role;
} else {
$role = 'public';
}
return $role;
}
示例6: getPanel
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
if ($this->_auth->hasIdentity()) {
$html = '<h4>Current Identity</h4>';
$html .= $this->_cleanData($this->_auth->getIdentity());
return $html;
}
return '';
}
示例7: getPanel
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$username = 'Not Authed';
$role = 'Unknown Role';
if ($this->_auth->hasIdentity()) {
foreach ($this->_auth->getIdentity() as $property => $value) {
$this->message->addRow(array((string) $property, (string) $value));
}
} else {
// $this->message->setMessage('Not authorized');
}
return '';
}
示例8: preDispatch
/**
*(non-PHPdoc)
*
* @see Zend_Controller_Plugin_Abstract::preDispatch()
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
/**
* Recupera a identidade do usuario logado
*
* @var Array
*/
$role = $this->auth->getIdentity();
/**
* Recursos que se deseja acesso
*
* @var String
*/
$resource = $this->getRequest()->getModuleName();
/**
* Ação permitida dentro de um resource
*
* @var String
*/
$action = $this->getRequest()->getModuleName() != 'admin' && $this->getRequest()->getModuleName() != 'sac' ? null : $this->getRequest()->getControllerName();
// Verificação condicional para os controllers e actions de upload
if (!($request->getActionName() == 'upload' || $request->getControllerName() == 'upload')) {
// Verifica se ha lixo na autenticacao
if (!is_array($role)) {
// Parametros
$params = array();
// Destroi qualquer instancia de autenticacao
$this->auth->clearIdentity();
// Altera a rota de destino
$request->setModuleName('admin')->setControllerName('login')->setActionName('index');
return;
}
// Verifica se o recurso existe e se o usuario logado tem acesso
if (!$this->acl->has($resource) || !$this->acl->isAllowed($role['usuario'], $resource, $action)) {
// Parametros
$params = array();
// Redireciona para o controller de login
if ($role['usuario'] != 'visitante') {
$params['erro'] = 'Você não possui permissão de acesso a este recurso.';
$request->setModuleName('admin')->setControllerName('index')->setActionName('index')->setParams($params);
} else {
if ($this->getRequest()->getModuleName() == "sac") {
$request->setModuleName('sac')->setControllerName('login')->setActionName('index')->setParams($params);
} else {
$request->setModuleName('admin')->setControllerName('login')->setActionName('index')->setParams($params);
}
}
return;
}
}
}
示例9: preDispatch
/**
* Called before an action is dispatched by Zend_Controller_Dispatcher.
*
* This callback allows for proxy or filter behavior. By altering the
* request and resetting its dispatched flag (via
* {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
* the current action may be skipped.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
// reset role & resource
Zend_Registry::set('Role', 'guest');
Zend_Registry::set('Resource', '');
// check if ErrorHandler wasn't fired
if ($request->getParam('error_handler')) {
return;
}
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
$pathInfo = $request->getPathInfo();
$allow = false;
if ($this->_auth->hasIdentity()) {
$userId = $this->_auth->getIdentity();
$roleId = $this->_auth->getRoleId();
$rolesList = $this->_em->find('Roles', $roleId);
$roleName = $rolesList->getRoleName();
$role = new Zend_Acl_Role($roleName);
} else {
$roleName = 'guest';
$role = new Zend_Acl_Role($roleName);
}
$resource = $action == '' ? trim($controller) . '/index' : trim($controller) . '/' . trim($action);
$resource = $module == 'default' ? $resource : $module . "/" . $resource;
// on main page resource might be empty
if ($resource == '') {
$resource = 'index/index';
}
// if resource not exist in db then check permission for controller
if (!$this->_acl->has($resource) && $action != '') {
$resource = trim($controller);
}
// check if user is allowed to see the page
$allow = $this->_acl->isAllowed($role, $resource);
if ($allow == false && $this->_auth->hasIdentity()) {
// user logged in but denied permission
$request->setModuleName('default');
$request->setControllerName('error');
$request->setActionName('forbidden');
/* $this->_response->setHeader('Content-type', 'text/html');
$this->_response->setHttpResponseCode(403);
$this->_response->setBody('<h1>403 - Forbidden</h1>');
$this->_response->sendResponse(); */
}
Zend_Registry::set('Role', $role);
Zend_Registry::set('Resource', $resource);
}
示例10: authInfo
/**
* Get authenticated users info
*
* @param object $inf (optional)
* @return logged users info
*/
public function authInfo($info = null)
{
if ($this->_zendAuth === null) {
$this->_zendAuth = Zend_Auth::getInstance();
}
if ($info === null) {
return $this;
}
if (false === $this->isLoggedIn()) {
return null;
}
$arrayObj = new ArrayObject($this->_zendAuth->getIdentity());
$iterator = $arrayObj->getIterator();
return $iterator[$info];
}
示例11: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($request->getParam('sid') !== null && $request->getParam('PHPSESSID') === null) {
$request->setParam('PHPSESSID', $request->getParam('sid'));
}
if ($request->getParam('PHPSESSID') === null) {
$module = strtolower($request->getModuleName());
$controller = strtolower($request->getControllerName());
$action = strtolower($request->getActionName());
$route = $module . '/' . $controller . '/' . $action;
if (!in_array($route, $this->_whitelist)) {
if (is_null($this->_auth)) {
$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session($this->getStorage()));
$this->_auth = $auth;
}
if (!$this->_auth->hasIdentity()) {
$errorHandler = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$errorHandler->type = 'EXCEPTION_NOT_ALLOWED';
$errorHandler->exception = new Zend_Controller_Action_Exception('No credentials available');
$errorHandler->request = clone $request;
$request->setParam('error_handler', $errorHandler)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction());
} else {
$this->_auth->getIdentity()->connect();
$this->_auth->getIdentity()->refresh();
}
}
}
}
示例12: preDispatch
/**
* Hook into action controller preDispatch() workflow
*
* @return void
*/
public function preDispatch()
{
$role = 'guest';
// die($role);
if ($this->_auth->hasIdentity()) {
$user = $this->_auth->getIdentity();
if (is_object($user)) {
$role = $this->_auth->getIdentity()->role;
}
}
$request = $this->_action->getRequest();
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
// $this->view->getLayout()->setLayout($module);
$this->_controllerName = $controller;
$resource = $controller;
$privilege = $action;
if (!$this->_acl->has($resource)) {
$resource = null;
}
if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
if (!$this->_auth->hasIdentity()) {
$noPermsAction = $this->_acl->getNoAuthAction();
} else {
$noPermsAction = $this->_acl->getNoAclAction();
}
$request->setModuleName($noPermsAction['module']);
$request->setControllerName($noPermsAction['controller']);
$request->setActionName($noPermsAction['action']);
$request->setDispatched(false);
}
}
示例13: preDispatch
/**
* Hook into action controller preDispatch() workflow
*
* @return void
*/
public function preDispatch()
{
$role = 'public';
if ($this->_auth->hasIdentity()) {
$user = $this->_auth->getIdentity();
if (is_object($user)) {
$role = $this->_auth->getIdentity()->role;
}
}
$request = $this->_action->getRequest();
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
$this->_controllerName = $controller;
$resource = $controller;
$privilege = $action;
if (!$this->_acl->has($resource)) {
$resource = null;
}
if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
$request->setModuleName('default');
$request->setControllerName('error');
$request->setActionName('error');
$request->setDispatched(false);
}
/**
if (!$this->_acl->isAllowed($role, $resource, $privilege)){
throw new Pas_Exception_NotAuthorised('Not authorised');
}
***/
}
示例14: delete
/**
* Delete user
*
* @param Newscoop\Entity\User $user
*
* @return void
*/
public function delete(User $user)
{
if ($this->auth->getIdentity() == $user->getId()) {
throw new \InvalidArgumentException("You can't delete yourself");
}
$this->getRepository()->delete($user);
}
示例15: getIdentity
/**
* Allows the ACL tighter integration with the identity
*
* @return string
*/
public function getIdentity()
{
if (null == $this->_identity && $this->_auth->hasIdentity()) {
$this->_identity = $this->_auth->getIdentity();
}
return $this->_identity;
}