/** * @param MvcEvent $e * @return mixed|void */ public function onDispatch(MvcEvent $e) { $this->sessionContainer->getDefaultManager()->forgetMe(); $this->sessionContainer->getDefaultManager()->expireSessionCookie(); $this->sessionContainer->getDefaultManager()->destroy(); $this->redirect()->toRoute('frontend'); }
public function testCanDisableContainerDefaultManagerInjectionViaConfiguration() { $config = array('session_manager' => array('enable_default_container_manager' => false)); $this->services->setService('Config', $config); $manager = $this->services->get('Zend\\Session\\ManagerInterface'); $this->assertNotSame($manager, Container::getDefaultManager()); }
/** * Retrieve the session manager * * If none composed, lazy-loads a SessionManager instance * * @return Manager */ public function getSessionManager() { if (!$this->session instanceof Manager) { $this->setSessionManager(Container::getDefaultManager()); } return $this->session; }
public function loginAction() { $redirect = $this->getRequest()->getQuery('redirect', false); $errors = []; if ($this->authentication->hasIdentity()) { return $this->redirect()->toRoute('dotuser'); } if ($this->getRequest()->isPost()) { $this->loginForm->setData($this->getRequest()->getPost()); $redirect = $this->getRequest()->getPost()->get('redirect', false); if ($this->loginForm->isValid()) { $authAdapter = $this->authentication->getAdapter(); $this->authentication->clearIdentity(); $params = $this->getRequest()->getPost(); $identity = $params->get('identity'); $credential = $params->get('credential'); $authAdapter->setIdentity($identity); $authAdapter->setCredential($credential); $result = $this->authentication->authenticate(); if ($result->isValid()) { $identity = $result->getIdentity(); $session = new Container($this->authentication->getStorage()->getNameSpace()); $session->getDefaultManager()->regenerateId(); if ($redirect) { return $this->redirect()->toUrl($redirect); } return $this->redirect()->toRoute('dotuser'); } else { $errors = array_merge($errors, $result->getMessages()); } } } //show login form return array('loginForm' => $this->loginForm, 'redirect' => $redirect, 'errors' => $errors); }
public function toCartAction() { $item_id = $this->getRequest()->getPost()->item_id; $item_quantity = $this->getRequest()->getPost()->item_quantity; $item_price = $this->getRequest()->getPost()->item_price; //die($item_id.'_'.$item_quantity.'_'.$item_price); //$item_id = $this->params()->fromRoute('id'); // need if non-ajax request $guest_session = new Container(); $guest_session->sessid = $guest_session->getDefaultManager()->getId(); $toExchange = $this->getCollectionTable()->fetchById($item_id)->toArray(); //$toExchange = $this->toArray($details); $toExchange[0]['cart_id'] = $guest_session->sessid; $toExchange[0]['item_quantity'] = $item_quantity; $toExchange[0]['item_price'] = $item_price; $cart_item = new Cart(); $cart_item->exchangeArray($toExchange[0]); $this->getCartTable()->insertCart($cart_item); /* return $this->redirect()->toRoute(NULL , array( 'controller' => 'collection', 'action' => 'index', )); */ /* // just check for workability $viewModel = new ViewModel(array( 'details' => $details, 'guest_session' => $guest_session )); return $viewModel; */ }
public function perform(Installer $installer) { $sessionManager = Container::getDefaultManager(); $sessionManager->start(); // Must explicitly clear storage since the session manager will // repopulate the session with old storage data. $sessionManager->destroy(['clear_storage' => true]); }
public function __invoke() { $user_session = new Container(); $cart_id = $user_session->getDefaultManager()->getId(); $result = $this->getServiceLocator()->getServiceLocator()->get('CartTable')->selectCartItemById($cart_id, $item_id = null, 'item_id'); $result = $this->toArray($result); return !is_null($result) ? 'img/cart-header-full.png' : 'img/cart-header-empty.png'; }
public function deconnexionAction() { $auth = new AuthenticationService(); $auth->clearIdentity(); $sessionManager = Container::getDefaultManager(); $sessionManager->destroy(); $this->flashMessenger()->addSuccessMessage('Vous avez bien été déconnecté(e).'); return $this->redirect()->toRoute('accueil'); }
public static function getSession($namespase = false) { $sessionContainer = Container::getDefaultManager(); $sessionStorage = $sessionContainer->getStorage(); if ($namespase) { return $sessionStorage->{$namespase}; } return $sessionStorage; }
public function logoutAction() { $auth = $this->getServiceLocator()->get('Omeka\\AuthenticationService'); $auth->clearIdentity(); $sessionManager = Container::getDefaultManager(); $sessionManager->destroy(); $this->messenger()->addSuccess('Successfully logged out'); return $this->redirect()->toRoute('login'); }
/** * Get CSRF validator * * @return \Zend\Validator\Csrf */ public function getCsrfValidator() { if (null === $this->csrfValidator) { $serviceLocator = $this->getServiceLocator(); if ($serviceLocator && $serviceLocator->has('Zend\\Session\\ManagerInterface')) { $defaultManager = SessionContainer::getDefaultManager(); $serviceManager = $serviceLocator->get('Zend\\Session\\ManagerInterface'); if ($defaultManager !== $serviceManager) { SessionContainer::setDefaultManager($serviceManager); } } } return parent::getCsrfValidator(); }
/** * Retrieve captcha (if any) * * @return null|ZendCaptcha\AdapterInterface */ public function getCaptcha() { if (null === $this->captcha) { $serviceLocator = $this->getServiceLocator(); if ($serviceLocator && $serviceLocator->has('Zend\\Session\\ManagerInterface')) { $defaultManager = SessionContainer::getDefaultManager(); $serviceManager = $serviceLocator->get('Zend\\Session\\ManagerInterface'); if ($defaultManager !== $serviceManager) { SessionContainer::setDefaultManager($serviceManager); } } if ($this->defaultCaptcha instanceof AdapterInterface) { $captcha = clone $this->defaultCaptcha; } else { $captcha = $this->defaultCaptcha; } $this->setCaptcha($captcha); } return parent::getCaptcha(); }
public function indexAction() { $sessStore = Container::getDefaultManager()->getStorage(); $key = md5($sessStore['c_secred'] . $sessStore['s_secred']); ob_start(); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $ciphertext_base64 = $this->request->getContent(); $ciphertext_dec = base64_decode($ciphertext_base64); # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($ciphertext_dec, 0, $iv_size); # retrieves the cipher text (everything except the $iv_size in the front) $ciphertext_dec = substr($ciphertext_dec, $iv_size); # may remove 00h valued characters from end of plain text $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); $plaintext_dec = '2' . $plaintext_dec . '2'; $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plaintext_dec, MCRYPT_MODE_CBC, $iv_dec); $ciphertext = base64_encode($iv_dec . $ciphertext); echo $ciphertext; $this->response->setContent(ob_get_clean()); return $this->response; }
/** * Metodo para cerrar la sesion * @return \Zend\View\Model\ViewModel */ public function logoutAction() { $content = new Container("cbol"); $content->getDefaultManager()->getStorage()->clear(); $this->layout('layout/login'); $auth = new \Zend\Authentication\AuthenticationService(); $auth->getStorage()->clear(); return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/login'); }
/** * @return \Zend\Http\Response */ public function processloginAction() { $this->getView()->setTemplate('application/login/index'); /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); if (!$request->isPost()) { return $this->redirect()->toUrl('/login'); } /* * @var LoginForm */ $form = $this->loginForm; $form->setInputFilter($form->getInputFilter()); $form->setData($request->getPost()); /* * See if form is valid */ if (!$form->isValid()) { $this->setLayoutMessages($form->getMessages(), 'error'); return $this->redirect()->toUrl('/login'); } $formData = $form->getData(); $adapter = $this->getAuthAdapter($formData); $auth = new AuthenticationService(); $result = $auth->authenticate($adapter); /* * See if authentication is valid */ if (!$result->isValid()) { $this->setLayoutMessages($result->getMessages(), 'error'); return $this->redirect()->toUrl('/login'); } $user = $result->getIdentity(); /* * If account is disabled/banned (call it w/e you like) clear user data and redirect */ if ((int) $user->isDisabled() === 1) { $this->setLayoutMessages($this->translate('LOGIN_ERROR'), 'error'); return $this->redirect()->toUrl('/login'); } $remote = new RemoteAddress(); $user->setLastLogin(date('Y-m-d H:i:s', time())); $user->setIp($remote->getIpAddress()); $this->getTable('SD\\Admin\\Model\\UserTable')->saveUser($user); $manager = Container::getDefaultManager(); if ($formData['rememberme'] == 1) { $manager->rememberMe(864000); //10 days $manager->getConfig()->setRememberMeSeconds(864000); } $manager->regenerateId(); $this->authService->getStorage()->write($user); // puts only id in session! return $this->redirect()->toUrl('/'); }
public function testDefaultManagerUsedWhenNoManagerProvided() { $manager = Container::getDefaultManager(); $container = new Container(); $this->assertSame($manager, $container->getManager()); }
/** * Get Session Manager * * @return Manager */ public function getManager() { if (null === $this->_manager) { $this->setManager(Container::getDefaultManager()); } return $this->_manager; }
public function getSessionManager() { if ($this->sessionManager === null) { $this->sessionManager = Container::getDefaultManager(); } return $this->sessionManager; }
protected function getCartId() { $user_session = new Container(); return $user_session->getDefaultManager()->getId(); }
/** * Configure Zend's default session manager. */ private function configureSession() { $sessionManager = Container::getDefaultManager(); $config = $sessionManager->getConfig(); $config->setOptions(['name' => md5(OMEKA_PATH), 'cookie_httponly' => true, 'use_strict_mode' => true, 'use_only_cookies' => true]); }
/** * Log visitor informations * * @param boolean $isPreview Is the current page is a preview * @param boolean $isAdmin Is an admin is connected * * @return void */ protected function logVisitor($isPreview, $isAdmin) { if (!$isPreview and !$isAdmin) { try { $visitor = new Visitor(); $session = new SessionContainer(); $sessionId = $session->getDefaultManager()->getId(); $session->visitorId = $visitor->getVisitorId($sessionId); } catch (Exception $e) { //don't care } } }
public function authenticate(AuthenticationEvent $event) { if ($this->isSatisfied()) { $storage = $this->getStorage()->read(); $event->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.')); return; } $identity = $event->getRequest()->getPost()->get('identity'); $credential = $event->getRequest()->getPost()->get('credential'); $credential = $this->preProcessCredential($credential); $userObject = null; // Cycle through the configured identity sources and test each $fields = $this->getOptions()->getAuthIdentityFields(); while (!is_object($userObject) && count($fields) > 0) { $mode = array_shift($fields); switch ($mode) { case 'username': $userObject = $this->getMapper()->findByUsername($identity); break; case 'email': $userObject = $this->getMapper()->findByEmail($identity); break; } } if (!$userObject) { $event->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.')); $this->setSatisfied(false); return false; } if ($this->getOptions()->getEnableUserState()) { // Don't allow user to login if state is not in allowed list if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) { $event->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.')); $this->setSatisfied(false); return false; } } $cryptoService = $this->getHydrator()->getCryptoService(); if (!$cryptoService->verify($credential, $userObject->getPassword())) { // Password does not match $event->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.')); $this->setSatisfied(false); return false; } elseif ($cryptoService instanceof Bcrypt) { // Update user's password hash if the cost parameter has changed $this->updateUserPasswordHash($userObject, $credential, $cryptoService); } // regen the id SessionContainer::getDefaultManager()->regenerateId(); // Success! $event->setIdentity($userObject->getId()); $this->setSatisfied(true); $storage = $this->getStorage()->read(); $storage['identity'] = $event->getIdentity(); $this->getStorage()->write($storage); $event->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.')); }