本文整理汇总了PHP中Zend_Auth::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Auth::getInstance方法的具体用法?PHP Zend_Auth::getInstance怎么用?PHP Zend_Auth::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Auth
的用法示例。
在下文中一共展示了Zend_Auth::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _checkAuthorization
/**
* Check authorization
*/
protected function _checkAuthorization()
{
$routeName = Zend_Controller_Front::getInstance()->getRouter()->hasRoute('admin') ? 'admin' : 'default';
$lang = $this->_request->getParam('lang');
if (!Zend_Auth::getInstance()->hasIdentity()) {
//if ajax request
if ($this->getRequest()->isXmlHttpRequest()) {
/*return $this->getHelper('json')->direct(array(
'success' => false,
'message' => $this->view->translate("Please login first")
));*/
throw new Zend_Controller_Action_Exception("Please login first", 403);
}
//store to return
$this->returnHere();
//redirect to login page
$this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'login', 'module' => 'admin', 'lang' => $lang), $routeName, true));
}
$aclLoader = HCMS_Acl_Loader::getInstance();
//check permission
if (!$aclLoader->getAcl()->isAllowed($aclLoader->getCurrentRoleCode(), $this->_authResourse, $this->_authPrivilege)) {
//redirect to login page
$this->_redirect($this->view->url(array('module' => 'admin', 'controller' => 'index', 'action' => 'login', 'lang' => $lang), $routeName, true));
throw new Zend_Controller_Action_Exception("You are not allowed to access this page", 403);
}
}
示例2: GetDadosUsuario
/**
* Helper para pegar as imagens do webservice
*
*/
public function GetDadosUsuario()
{
$auth = Zend_Auth::getInstance();
$db = Zend_Db_Table::getDefaultAdapter();
$chAction = strtolower(Zend_Controller_Front::getInstance()->getRequest()->getActionName());
$chController = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$sql = 'select ';
$sql .= ' u.*, ';
$sql .= ' a.nm_avatar, ';
$sql .= ' a.tp_avatar, ';
$sql .= ' a.sz_avatar, ';
$sql .= ' a.arquivo ';
$sql .= 'from ';
$sql .= ' sca_usuario u ';
$sql .= ' left join sgg_avatar a on a.id_avatar = u.id_avatar ';
$sql .= 'where u.st_usuario = 1 ';
$sql .= 'and u.id_usuario = ' . $auth->getIdentity()->id_usuario;
$result = $db->fetchRow($sql);
if ($result) {
if ($result['arquivo']) {
$result['arquivo'] = "data:" . $result['tp_avatar'] . ";base64," . base64_encode($result['arquivo']);
}
}
return $result;
}
示例3: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$auth = Zend_Auth::getInstance();
$isAllowed = false;
$controller = $request->getControllerName();
$action = $request->getActionName();
// Generate the resource name
$resourceName = $controller . '/' . $action;
// Don't block errors
if ($resourceName == 'error/error') {
return;
}
$resources = $this->acl->getResources();
if (!in_array($resourceName, $resources)) {
$request->setControllerName('error')->setActionName('error')->setDispatched(true);
throw new Zend_Controller_Action_Exception('This page does not exist', 404);
return;
}
// Check if user can access this resource or not
$isAllowed = $this->acl->isAllowed(Zend_Registry::get('role'), $resourceName);
// Forward user to access denied or login page if this is guest
if (!$isAllowed) {
if (!Zend_Auth::getInstance()->hasIdentity()) {
$forwardAction = 'login';
} else {
$forwardAction = 'deny';
}
$request->setControllerName('index')->setActionName($forwardAction)->setDispatched(true);
}
}
示例4: indexAction
public function indexAction()
{
// display the profile form and populate if profile exists
$request = $this->getRequest();
$form = new Application_Form_Profile();
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$profileMapper = new Application_Model_ProfileMapper();
$profile = new Application_Model_Profile();
$exists = $profileMapper->exists($identity->id);
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$profile->setOptions($form->getValues());
$profile->setUserId($identity->id);
$profileMapper->save($profile, $exists);
// display success message
$this->view->msg = "<p class='msg'>Profile saved</p>";
}
} else {
$profileMapper->find($identity->id, $profile);
$data = array('first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'birthdate' => date_format(new DateTime($profile->getBirthdate()), 'Y-m-d'), 'gender' => $profile->getGender());
$form->populate($data);
}
$this->view->form = $form;
}
示例5: preRender
public function preRender()
{
if (Zend_Auth::getInstance()->hasIdentity()) {
$controller = sgContext::getInstance()->getController();
if ($controller instanceof FlatCMSPluginController) {
$session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace());
$session->FlatCMSEditorPluginFileMTime = filemtime(FlatCMSPluginPageModel::getPagePath(sgContext::getInstance()->getCurrentPath()));
//figure out better way to handle this so libraries aren't double loaded
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.min.js');
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.mini.js');
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.autogrow.js');
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/tinymce/jscripts/tiny_mce/jquery.tinymce.js');
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.tinymce.js');
$controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/init.js');
$controller->js_settings['FlatCMSEditorPlugin'] = array('saveURL' => sgToolkit::url(sgConfiguration::get('routing.FlatCMSEditorPlugin_save.path')), 'currentPath' => sgContext::getInstance()->getCurrentPath());
if (isset($controller->content) && is_array($controller->content)) {
$textarea_fields = sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields', array());
foreach ($controller->content as $key => &$field) {
if (in_array($key, $textarea_fields)) {
$field = '<div class="editable-area" id="' . $key . '">' . $field . '</div>';
} else {
$field = '<div class="editable" id="' . $key . '">' . $field . '</div>';
}
}
}
}
}
}
示例6: preDispatch
function preDispatch()
{
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()) {
$this->_redirect('auth/login');
}
}
示例7: loggedInAs
public function loggedInAs()
{
$Auth = Zend_Auth::getInstance();
$Ret = '';
if ($Auth->hasIdentity()) {
$Username = $Auth->getIdentity()->Nome . ' ' . $Auth->getIdentity()->Cognome;
$Module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
$LogoutURL = $this->view->url(array('controller' => 'login', 'action' => 'logout', 'module' => 'default'), 'default', true);
$MessaggiURL = $this->view->url(array('controller' => 'messages', 'action' => 'index', 'module' => 'default'), 'default');
$AdminURL = $this->view->url(array('controller' => 'index', 'action' => 'index', 'module' => $Module == 'admin' ? 'default' : 'admin'), 'default');
#$Ret .= 'Welcome ' . $Username . ' ';
$Ret .= '<a href="' . $MessaggiURL . '">' . $this->view->img('images/icons/mail_24x24.png', array('title' => 'Messages', 'alt' => 'Messages')) . '</a> ';
$Ret .= '<a href="' . $AdminURL . '">' . $this->view->img('images/icons/' . ($Module == 'admin' ? 'magic_wand' : 'wrench') . '_24x24.png', array('title' => $Module == 'admin' ? 'Public' : 'Admin', 'alt' => $Module == 'admin' ? 'Public' : 'Admin')) . '</a> ';
$Ret .= '<a href="' . $LogoutURL . '">' . $this->view->img('images/icons/lock_24x24.png', array('title' => 'Logout', 'alt' => 'Logout')) . '</a>';
return $Ret;
}
$Request = Zend_Controller_Front::getInstance()->getRequest();
$Controller = $Request->getControllerName();
$Action = $Request->getActionName();
if ($Controller == 'login' && $Action == 'index') {
return '';
}
$LoginURL = $this->view->url(array('controller' => 'login', 'action' => 'index'), 'default');
$Ret .= '<a href="' . $LoginURL . '">' . $this->view->img('images/icons/unlock_24x24.png', array('title' => 'Login', 'alt' => 'Login')) . '</a>';
return $Ret;
}
示例8: __construct
public function __construct($tthis, $context, $data)
{
$this->tthis = $tthis;
$this->context = $context;
$this->data = $data;
$year = 0;
if (isset($tthis->_attributes['year'])) {
$year = (int) $tthis->_attributes['year'];
}
if (!$year > 0) {
$year = date('Y') - 1;
}
// default year to previous
$this->dateStart = date('Y-m-d', strtotime($year . '-01-01'));
$this->dateEnd = date('Y-m-d', strtotime($year . '-12-31'));
$this->providerId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
$providerId = (int) $this->context;
if ($providerId > 0) {
$this->providerId = $providerId;
}
$info = array();
$info['dateStart'] = $this->dateStart;
$info['dateEnd'] = $this->dateEnd;
$provider = new Provider();
$provider->personId = $this->providerId;
$provider->populate();
$info['provider'] = $provider;
self::$info = $info;
}
示例9: init
function init()
{
$auth = Zend_Auth::getInstance();
$this->_userInfo = $auth->getIdentity();
$this->_dirApp = Zend_Registry::get('dirApp')->toArray();
$this->view = Myapp_View_Smarty::getInstance();
$this->view->setView($this->_dirApp['template_front'] . $this->_dirApp['style'] . '/');
$smarty = $this->view->getEngine();
$smarty->compile_dir = $this->_dirApp['template_front_cache'];
$viewRenderer = $this->_helper->getHelper('viewRenderer');
$viewRenderer->setView($this->view)->setViewBasePathSpec($smarty->template_dir)->setViewScriptPathSpec(':controller/:action.:suffix')->setViewScriptPathNoControllerSpec(':action.:suffix')->setViewSuffix($this->_dirApp['template_extension']);
$this->_base_url = $this->_dirApp['base_url'];
$this->view->assign('base_url', $this->_base_url);
$this->view->assign('base_tpl', $this->_dirApp['base_tpl']);
$this->_model = Front_Model_Lang::getInstance();
$this->_module = $this->_getParam('module');
$this->_control = $this->_getParam('controller');
$action = $this->_getParam('action');
$this->view->assign('form', array('module' => $this->_module, 'control' => $this->_control, 'action' => $action, 'lang' => $_SESSION['lang']));
$this->_lable = Zend_Registry::get('lable');
$this->view->assign('lable', $this->_lable);
if (empty($this->_userInfo->adminId)) {
$this->_redirect($this->_base_url . 'login/');
}
if ($this->_userInfo->adminId != '') {
$file_name = $this->_dirApp['dir_auth'] . $this->_userInfo->adminLogin . '.ini';
$sessionAuth = Myapp_File_Createauth::getInstance()->compareSession($file_name);
if ($sessionAuth == true) {
$this->_redirect($this->_base_url . 'logout/');
}
}
$this->view->assign('userInfo', $this->_userInfo);
}
示例10: authAction
public function authAction()
{
$request = $this->getRequest();
// Check if we have a POST request
if (!$request->isPost()) {
die('not posted');
//return $this->_helper->redirector('index');
}
// Get our form and validate it
$form = $this->_loginForm;
if (!$form->isValid($request->getPost())) {
// Invalid entries
$this->view->loginForm = $form;
return $this->render('index');
// re-render the login form
}
// Get our authentication adapter and check credentials
$adapter = $this->getAuthAdapter($form->getValues());
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if (!$result->isValid()) {
// Invalid credentials
$form->setDescription('Invalid credentials provided');
$this->view->loginForm = $form;
return $this->render('index');
// re-render the login form
}
die("We're authenticated! Redirect to the home page");
//$this->_helper->redirector('poll', 'index');
}
示例11: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$loginController = 'authentication';
$loginAction = 'login';
$auth = Zend_Auth::getInstance();
// If user is not logged in and is not requesting login page
// - redirect to login page.
if (!$auth->hasIdentity() && $request->getControllerName() != $loginController && $request->getActionName() != $loginAction) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$redirector->gotoSimpleAndExit($loginAction, $loginController);
}
// User is logged in or on login page.
if ($auth->hasIdentity()) {
// Is logged in
// Let's check the credential
$acl = new Tynex_Models_TynexAcl();
$identity = $auth->getIdentity();
// role is a column in the user table (database)
$isAllowed = $acl->isAllowed($identity->role, $request->getControllerName(), $request->getActionName());
if (!$isAllowed) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$redirector->gotoUrlAndExit('/');
}
}
}
示例12: assert
/**
* Returns true if and only if the assertion conditions are met
*
* This method is passed the ACL, Role, Resource, and privilege to which
* the authorization query applies. If the $role, $resource, or $privilege
* parameters are null, it means that the query applies to all Roles,
* Resources, or privileges, respectively.
*
* @param Zend_Acl $acl
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Resource_Interface $resource
* @param string $privilege
* @return boolean
*/
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
{
// We need specific objects to check against each other
if (NULL === $role || NULL === $resource) {
return false;
}
// Ensure we're handled User models
if (!$role instanceof UserModel) {
throw new Exception('Role must be an instance of UserModel');
}
if (!$resource instanceof WatcherModel) {
throw new Exception('Resource must be an instance of WatcherModel');
}
switch ($resource->scope) {
case 'user':
return $role->id == $resource->scopeId;
case 'apiId':
if (!$role instanceof \Application\Model\CurrentUserModel || !$role->isApiAuthUser()) {
return FALSE;
}
return $role->apiId == $resource->scopeId;
case 'token':
if (Zend_Auth::getInstance()->hasIdentity() && ($ident = Zend_Auth::getInstance()->getIdentity()) && isset($ident['token'])) {
return $ident['token'] === $resource->scopeId;
}
return false;
case 'organization':
return $role->organizationId === $resource->scopeId;
}
return false;
}
示例13: getAuth
/**
* Get the auth object
*
* @return Zend_Auth
*/
public function getAuth()
{
if (null === $this->_auth) {
$this->_auth = Zend_Auth::getInstance();
}
return $this->_auth;
}
示例14: confirmTrialAction
public function confirmTrialAction()
{
$subscription_id = $this->_getParam('id');
$subscription = Engine_Api::_()->getItem('payment_subscription', $subscription_id);
if ($subscription) {
//save tracking
$trialPlanTable = Engine_Api::_()->getDbTable('trialplans', 'user');
$trialRow = $trialPlanTable->getRow($subscription->user_id, $subscription->package_id);
if (isset($trialRow)) {
return $this->_helper->requireSubject()->forward();
} else {
$trialRow = $trialPlanTable->createRow();
$trialRow->package_id = $subscription->package_id;
$trialRow->user_id = $subscription->user_id;
$trialRow->active = true;
$package = $subscription->getPackage();
if (isset($package)) {
$trialRow->level_id = $package->level_id;
}
$trialRow->save();
}
$this->view->verified = true;
$this->view->approved = true;
$subscription->status = 'pending';
$subscription->active = true;
$subscription->save();
$subscription->onTrialPaymentSuccess();
//set login for viewer
Zend_Auth::getInstance()->getStorage()->write($subscription->user_id);
Engine_Api::_()->user()->setViewer();
$this->view->viewer_id = $subscription->user_id;
}
}
示例15: assert
public function assert(Core_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
{
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()) {
return false;
}
$controller = Controlador::getInstance();
$usuario = $controller->usuario;
if (!$controller->cache->test('privilegio_' . $usuario->ID . '_' . $resource->id)) {
// não existe o cache, pegar o valor do banco
$privilegio = DaoRecurso::getPrivilegioByUsuario($usuario, $resource);
$controller->cache->save($privilegio, 'privilegio_' . $usuario->ID . '_' . $resource->id, array('acl_usuario_' . $usuario->ID, 'acl_unidade_' . $usuario->ID_UNIDADE));
} else {
$privilegio = $controller->cache->load('privilegio_' . $usuario->ID . '_' . $resource->id);
}
// Checa se o usuario tem permissao de acessar o recurso incondicionalmente
if ($acl->has($resource) && $privilegio) {
return true;
} else {
$contexto = $resource->getContexto();
if (!is_null($contexto) && count($contexto) > 0) {
// Existe um contexto, avaliar se o id_unid_area_trabalho do objeto contexto == ID_UNIDADE do usuario logado
return $contexto['id_unid_area_trabalho'] == $usuario->ID_UNIDADE;
} else {
// Não existe objeto de contexto, retorna true se recurso original da requisicao for AREA DE TRABALHO
return Controlador::getInstance()->recurso->id == 3;
}
}
return false;
}