/** * Construtor do Plugin * * @param $acl Zend_Acl * @param $auth Zend_Auth */ public function __construct($dbAdapter) { // Carrega todas as ACl's $this->acl = new Acl_Global($dbAdapter); // Recupera a informacao de autenticacao $this->auth = Zend_Auth::getInstance(); // Adiciona o role padrao de visitante if (!$this->auth->hasIdentity()) { $authStorage = $this->auth->getStorage(); $authStorage->write(array('usuario' => 'visitante', 'role' => 'visitante')); } }
/** * Check permissions before dispatch process * * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible * @param Zend_Controller_Request_Abstract $request * @return void */ public function preDispatch(Zend_Controller_Request_Abstract $request) { $resource = $request->getControllerName(); $action = $request->getActionName(); if ($this->_auth->hasIdentity()) { $identity = $this->_auth->getStorage()->read(); $role = $identity->role; } else { $role = $this->_defaultRole; } if ($this->_acl->has($resource) && !$this->_acl->isAllowed($role, $resource, $action)) { $request->setControllerName('error')->setActionName('deny'); } }
/** * Возвращает объект-хранилище данных по авторизации * * @return Zend_Auth_Storage_Interface */ public function getStorage() { if (true == Zend_Registry::get('config')->Access->cookie && Zend_Controller_Front::getInstance()->getRequest()->getParam('use_cookie')) { $this->setStorage(new Modules_Access_Framework_Auth_Storage_Cookie()); } return parent::getStorage(); }
/** * Reference list action * */ public function referencesAction() { $this->_setMetaTitle('My HomeLet | References'); $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/references' => 'My References')); // Get the customer session $customerSession = $this->auth->getStorage()->read(); $request = $this->getRequest(); // Search and ordering $filteredOrderBy = array(); $orderBy = $request->getParam('order'); $refnoSearch = $request->getParam('id'); // Validate order by to restricted fields to those displayed on the front end if (is_array($orderBy)) { foreach ($orderBy as $orderByField => $orderByDirection) { if (in_array($orderByField, array('start_date', 'lastname', 'address1', 'externalrefno', 'status'))) { // Copy field into new array $filteredOrderBy[$orderByField] = $orderByDirection; } } } // Get list of external reference numbers $referencesAndReports = array(); $referenceManager = new Manager_Referencing_Reference(); $referenceIds = $referenceManager->getAllReferenceIds($customerSession->id); // Get all reference details $legacyRefManager = new Manager_ReferencingLegacy_Munt(); $references = $legacyRefManager->getAllReferences($referenceIds, $refnoSearch, $filteredOrderBy); foreach ($references as $reference) { $report = $legacyRefManager->getLatestReport($reference->externalId); array_push($referencesAndReports, array('reference' => $reference, 'report' => $report)); } $this->view->references = $referencesAndReports; }
public function authenticate($username, $password) { $doctrineAuthAdapter = new Neo_Doctrine_Auth_Adapter(Doctrine_core::getConnectionByTableName('Usuario')); $doctrineAuthAdapter->setTableName('Usuario u')->setIdentityColumn('u.email')->setCredentialColumn('u.password')->setIdentity($username)->setCredential(md5($password)); if ('backend' === $this->_module) { //$doctrineAuthAdapter->setCredentialTreatment("MD5(?) AND c.status = true AND c.admin = true"); } else { //$doctrineAuthAdapter->setCredentialTreatment("MD5(?) AND c.status = true AND c.admin = false"); } $authResult = $this->_auth->authenticate($doctrineAuthAdapter); switch ($authResult->getCode()) { case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND: $this->_flashMessenger->addError($this->_message[self::NOT_IDENTITY]); break; case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID: $this->_flashMessenger->addError($this->_message[self::INVALID_CREDENTIAL]); break; case Zend_Auth_Result::SUCCESS: if ($authResult->isValid()) { $identity = $doctrineAuthAdapter->getResultRowObject('id', 'password', 'admin'); $this->_auth->getStorage()->write($identity); } else { $this->_flashMessenger->addError($this->_message[self::INVALID_USER]); } break; default: $this->_flashMessenger->addError($this->_message[self::INVALID_LOGIN]); break; } return $this->_auth; }
/** * Retrieve the document * * @param string $policyNumber Policy number * @param string $documentId Unique document request hash * @return string null or PDF contents */ private function _fetchDocument($policyNumber, $documentId) { // Get the customer session $customerSession = $this->auth->getStorage()->read(); // Get the request policy if ($policyNumber[0] == 'Q') { // Quotes $legacyPolicies = new Datasource_Insurance_LegacyQuotes(); } else { // Policies $legacyPolicies = new Datasource_Insurance_LegacyPolicies(); } $policy = $legacyPolicies->getByPolicyNumber($policyNumber); if (!$policy) { return null; } // Check the policy customer refno is linked to the customer id through mapping $customerMaps = new Datasource_Core_CustomerMaps(); $customerMap = $customerMaps->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $policy->refNo); // Confirm the policy number belongs to the logged in customer if ($customerMap == false || $customerMap->getIdentifier() != $customerSession->id) { // Customer map not found or customer is not mapped to refno, render error message return null; } // Get all document details $documentHistory = new Datasource_Insurance_DocumentHistory(); $document = $documentHistory->getDocument($documentId, $policyNumber); if (!$document) { return null; } // Retrieve document from store $documentFulfillmentService = new Service_Insurance_Document(); return $documentFulfillmentService->retrieveDocumentFromStore($documentId, $document->template_name, Service_Insurance_Document::DOCUMENT_AND_ATTACHMENTS); }
/** * Retrieves a role from the current identity * * @return null|string */ public function getIdentityRole() { if (!$this->_auth->hasIdentity()) { return null; } $storage = $this->_auth->getStorage()->read(); return $storage->role; }
public function forceAuthenticate($userUuid) { // Get a reference to the singleton instance of Zend_Auth $this->_auth = Zend_Auth::getInstance(); // Set the storage interface $this->_auth->setStorage(new Glo_Auth_Storage_Session('Glo_Auth')); $storage = $this->_auth->getStorage(); $data = new stdClass(); $data->user_uuid = $userUuid; $storage->write($data); return; }
/** * @return Zend_Auth_Result */ public function authenticate(Zend_Auth $auth, $username, $password, $persistIfSuccessful = true) { $adapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table_Abstract::getDefaultAdapter(), 'user', 'username', 'user_credential.value'); $adapterSelect = $adapter->getDbSelect()->join('user_credential', 'user_credential.user_id = user.id')->where('user_credential.type = "PASSWORD"'); $adapter->setIdentity($username)->setCredential(md5($password)); // SQLite has no internal md5() function $authResult = $auth->authenticate($adapter); if (!$authResult->isValid() || $persistIfSuccessful == false) { return $authResult; } $userInfo = $adapter->getResultRowObject(array('id', 'username')); /** NEEDS TO BE IMPLEMENTED **/ // Store all user details except password in authentication session $auth->getStorage()->write($currentUser); return $authResult; }
/** Identify the user * @access public * @return void */ public function identifyAction() { if ($this->getRequest()->isPost()) { $formData = $this->_getFormData(); if (empty($formData['username']) || empty($formData['password'])) { $this->getFlash()->addMessage('Please provide a username and password.'); } else { // do the authentication $authAdapter = $this->_getAuthAdapter($formData); $result = $this->_auth->authenticate($authAdapter); if (!$result->isValid()) { $this->getFlash()->addMessage('Login failed'); } else { $data = $authAdapter->getResultRowObject(null, 'password'); $this->_auth->getStorage()->write($data); $this->redirect(self::REDIRECT); } } } }
/** On success action * @access public * @return void */ public function successAction() { if (null === $this->_auth->getIdentity()) { $this->view->headTitle('Login to the system'); $form = new LoginForm(); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $authAdapter = $form->username->getValidator('Authorise')->getAuthAdapter(); $data = $authAdapter->getResultRowObject(null, 'password'); $this->_auth->getStorage()->write($data); $this->redirect($this->_helper->loginRedirect()); } else { $this->_auth->clearIdentity(); $this->getFlash()->addMessage('Sorry, there was a problem with your submission. Please check and try again'); $form->populate($formData); } } } else { $this->redirect('/users/'); } }
/** * @return boolean */ public function storageUser(stdClass $user) { $this->_zendAuth->getStorage()->write($user); $authNamespace = new Zend_Session_Namespace('auth'); $authNamespace->timeout = time() + __MAXIMO_MINUTOS_SESSAO__ * 60; }
public function init() { $customer = $this->auth->getStorage()->read(); // Set custom subform decorator $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/logged-in.phtml', 'customer' => $customer)))); }
/** * Get namespace of a session * * @return string session namespace */ public function getNamespace() { return $this->_zendAuth->getStorage()->getNamespace(); }