/** * Disabled form security in order to prevent exit from the app * @magentoConfigFixture current_store admin/security/session_lifetime 59 */ public function testIsLoggedInWithIgnoredLifetime() { $this->_auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $this->assertTrue($this->_model->isLoggedIn()); $this->_model->setUpdatedAt(time() - 101); $this->assertTrue($this->_model->isLoggedIn()); }
/** * Prepare and do request to shipment * * @param Shipment $orderShipment * @return \Magento\Framework\DataObject * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function requestToShipment(Shipment $orderShipment) { $admin = $this->_authSession->getUser(); $order = $orderShipment->getOrder(); $shippingMethod = $order->getShippingMethod(true); $shipmentStoreId = $orderShipment->getStoreId(); $shipmentCarrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode()); $baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode(); if (!$shipmentCarrier) { throw new LocalizedException(__('Invalid carrier: %1', $shippingMethod->getCarrierCode())); } $shipperRegionCode = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $shipmentStoreId); if (is_numeric($shipperRegionCode)) { $shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode(); } $originStreet1 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS1, ScopeInterface::SCOPE_STORE, $shipmentStoreId); $storeInfo = new DataObject((array) $this->_scopeConfig->getValue('general/store_information', ScopeInterface::SCOPE_STORE, $shipmentStoreId)); if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !$shipperRegionCode || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, ScopeInterface::SCOPE_STORE, $shipmentStoreId)) { throw new LocalizedException(__('We don\'t have enough information to create shipping labels. Please make sure your store information and settings are complete.')); } /** @var $request \Magento\Shipping\Model\Shipment\Request */ $request = $this->_shipmentRequestFactory->create(); $request->setOrderShipment($orderShipment); $address = $order->getShippingAddress(); $this->setShipperDetails($request, $admin, $storeInfo, $shipmentStoreId, $shipperRegionCode, $originStreet1); $this->setRecipientDetails($request, $address); $request->setShippingMethod($shippingMethod->getMethod()); $request->setPackageWeight($order->getWeight()); $request->setPackages($orderShipment->getPackages()); $request->setBaseCurrencyCode($baseCurrencyCode); $request->setStoreId($shipmentStoreId); return $shipmentCarrier->requestToShipment($request); }
/** * Prepare and do request to shipment * * @param Shipment $orderShipment * @return \Magento\Framework\Object * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function requestToShipment(Shipment $orderShipment) { $admin = $this->_authSession->getUser(); $order = $orderShipment->getOrder(); $address = $order->getShippingAddress(); $shippingMethod = $order->getShippingMethod(true); $shipmentStoreId = $orderShipment->getStoreId(); $shipmentCarrier = $this->_carrierFactory->create($order->getShippingMethod(true)->getCarrierCode()); $baseCurrencyCode = $this->_storeManager->getStore($shipmentStoreId)->getBaseCurrencyCode(); if (!$shipmentCarrier) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid carrier: %1', $shippingMethod->getCarrierCode())); } $shipperRegionCode = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_REGION_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId); if (is_numeric($shipperRegionCode)) { $shipperRegionCode = $this->_regionFactory->create()->load($shipperRegionCode)->getCode(); } $recipientRegionCode = $this->_regionFactory->create()->load($address->getRegionId())->getCode(); $originStreet1 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId); $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId); $storeInfo = new \Magento\Framework\Object((array) $this->_scopeConfig->getValue('general/store_information', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)); if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !$shipperRegionCode || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId) || !$this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)) { throw new \Magento\Framework\Exception\LocalizedException(__('We don\'t have enough information to create shipping labels. Please make sure your store information and settings are complete.')); } /** @var $request \Magento\Shipping\Model\Shipment\Request */ $request = $this->_shipmentRequestFactory->create(); $request->setOrderShipment($orderShipment); $request->setShipperContactPersonName($admin->getName()); $request->setShipperContactPersonFirstName($admin->getFirstname()); $request->setShipperContactPersonLastName($admin->getLastname()); $request->setShipperContactCompanyName($storeInfo->getName()); $request->setShipperContactPhoneNumber($storeInfo->getPhone()); $request->setShipperEmail($admin->getEmail()); $request->setShipperAddressStreet(trim($originStreet1 . ' ' . $originStreet2)); $request->setShipperAddressStreet1($originStreet1); $request->setShipperAddressStreet2($originStreet2); $request->setShipperAddressCity($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)); $request->setShipperAddressStateOrProvinceCode($shipperRegionCode); $request->setShipperAddressPostalCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)); $request->setShipperAddressCountryCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipmentStoreId)); $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname())); $request->setRecipientContactPersonFirstName($address->getFirstname()); $request->setRecipientContactPersonLastName($address->getLastname()); $request->setRecipientContactCompanyName($address->getCompany()); $request->setRecipientContactPhoneNumber($address->getTelephone()); $request->setRecipientEmail($address->getEmail()); $request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2))); $request->setRecipientAddressStreet1($address->getStreetLine(1)); $request->setRecipientAddressStreet2($address->getStreetLine(2)); $request->setRecipientAddressCity($address->getCity()); $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode()); $request->setRecipientAddressRegionCode($recipientRegionCode); $request->setRecipientAddressPostalCode($address->getPostcode()); $request->setRecipientAddressCountryCode($address->getCountryId()); $request->setShippingMethod($shippingMethod->getMethod()); $request->setPackageWeight($order->getWeight()); $request->setPackages($orderShipment->getPackages()); $request->setBaseCurrencyCode($baseCurrencyCode); $request->setStoreId($shipmentStoreId); return $shipmentCarrier->requestToShipment($request); }
/** * Run installation in context of the specified admin user * * @param $userName * @param array $modules * @return void * @throws \Exception */ public function run($userName, array $modules = []) { set_time_limit(0); /** @var \Magento\User\Model\User $user */ $user = $this->userFactory->create()->loadByUsername($userName); if (!$user->getId()) { throw new \Exception('Invalid admin user provided'); } $this->state->start(); $this->session->setUser($user); $this->deploy->run(); $resources = $this->initResources($modules); $this->state->clearErrorFlag(); try { foreach ($this->moduleList->getNames() as $moduleName) { if (isset($resources[$moduleName])) { $resourceType = $resources[$moduleName]; $this->setupFactory->create($resourceType)->run(); $this->postInstaller->addModule($moduleName); } } $this->session->unsUser(); $this->postInstaller->run(); $this->state->finish(); } catch (\Exception $e) { $this->state->setError(); $this->logger->log($e->getMessage()); } }
/** * Match provided request and if matched - return corresponding controller * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\Action\Action|null */ public function match(\Magento\Framework\App\RequestInterface $request) { // if URL has VDE prefix if (!$this->_designEditorHelper->isVdeRequest($request)) { return null; } // user must be logged in admin area if (!$this->_session->isLoggedIn()) { return null; } // prepare request to imitate $this->_prepareVdeRequest($request); /** * Deprecated line of code was here which should be adopted if needed: * $this->_urlRewriteService->applyRewrites($request); */ // match routers $controller = null; $routers = $this->_getMatchedRouters(); /** @var $router \Magento\Framework\App\RouterInterface */ foreach ($routers as $router) { /** @var $controller \Magento\Framework\App\Action\AbstractAction */ $controller = $router->match($request); if ($controller) { $this->_state->update(\Magento\Framework\App\Area::AREA_FRONTEND, $request); break; } } // set inline translation mode $this->_designEditorHelper->setTranslationMode($request); return $controller; }
/** * Retrieve current role * * @return string|null */ public function getAclRoleId() { if ($this->_session->hasUser()) { return $this->_session->getUser()->getAclRole(); } return null; }
/** * {@inheritdoc} */ protected function _prepareForm() { $userId = $this->_authSession->getUser()->getId(); $user = $this->_userFactory->create()->load($userId); $user->unsetData('password'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]); $fieldset->addField('username', 'text', ['name' => 'username', 'label' => __('User Name'), 'title' => __('User Name'), 'required' => true]); $fieldset->addField('firstname', 'text', ['name' => 'firstname', 'label' => __('First Name'), 'title' => __('First Name'), 'required' => true]); $fieldset->addField('lastname', 'text', ['name' => 'lastname', 'label' => __('Last Name'), 'title' => __('Last Name'), 'required' => true]); $fieldset->addField('user_id', 'hidden', ['name' => 'user_id']); $fieldset->addField('email', 'text', ['name' => 'email', 'label' => __('Email'), 'title' => __('User Email'), 'required' => true]); $fieldset->addField('password', 'password', ['name' => 'password', 'label' => __('New Password'), 'title' => __('New Password'), 'class' => 'input-text validate-admin-password']); $fieldset->addField('confirmation', 'password', ['name' => 'password_confirmation', 'label' => __('Password Confirmation'), 'class' => 'input-text validate-cpassword']); $fieldset->addField('interface_locale', 'select', ['name' => 'interface_locale', 'label' => __('Interface Locale'), 'title' => __('Interface Locale'), 'values' => $this->_localeLists->getTranslatedOptionLocales(), 'class' => 'select']); $verificationFieldset = $form->addFieldset('current_user_verification_fieldset', ['legend' => __('Current User Identity Verification')]); $verificationFieldset->addField(self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'password', ['name' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'label' => __('Your Password'), 'id' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'title' => __('Your Password'), 'class' => 'input-text validate-current-password required-entry', 'required' => true]); $data = $user->getData(); unset($data[self::IDENTITY_VERIFICATION_PASSWORD_FIELD]); $form->setValues($data); $form->setAction($this->getUrl('adminhtml/system_account/save')); $form->setMethod('post'); $form->setUseContainer(true); $form->setId('edit_form'); $this->setForm($form); return parent::_prepareForm(); }
/** * Predispath admin action controller * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->backendAuthSession->isLoggedIn()) { $feedModel = $this->feedFactory->create(); $feedModel->checkUpdate(); } }
/** * Check whether survey question can show * * @return bool */ public function isDisplayed() { if ($this->_authSession->getHideSurveyQuestion() || false == $this->_authorization->isAllowed(null) || $this->_survey->isSurveyViewed() || false == $this->_survey->isSurveyUrlValid()) { return false; } return true; }
/** * @dataProvider loginDataProvider */ public function testIsLoggedIn($loggedIn) { if ($loggedIn) { $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); } $this->assertEquals($loggedIn, $this->authSession->isLoggedIn()); }
/** * @param int|null $userId * @return void */ public function setupUserId($userId) { $this->adminSession->expects($this->once())->method('hasUser')->will($this->returnValue($userId)); if ($userId) { $this->adminSession->expects($this->once())->method('getUser')->will($this->returnSelf()); $this->adminSession->expects($this->once())->method('getId')->will($this->returnValue($userId)); } }
/** * @param string $locale * @dataProvider switchBackendInterfaceLocaleDataProvider * @covers \Magento\Backend\Model\Locale\Manager::switchBackendInterfaceLocale */ public function testSwitchBackendInterfaceLocale($locale) { $this->_model->switchBackendInterfaceLocale($locale); $userInterfaceLocale = $this->_authSession->getUser()->getInterfaceLocale(); $this->assertEquals($userInterfaceLocale, $locale); $sessionLocale = $this->_session->getSessionLocale(); $this->assertEquals($sessionLocale, null); }
/** * Predispath admin action controller * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_backendAuthSession->isLoggedIn()) { $feedModel = $this->_feedFactory->create(); /* @var $feedModel \Magento\AdminNotification\Model\Feed */ $feedModel->checkUpdate(); } }
/** * @return bool */ public function hasAvailableResources() { $user = $this->_authSession->getUser(); if ($user && $user->getHasAvailableResources()) { return true; } return false; }
/** * Report system cache is flushed to New Relic * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { $user = $this->backendAuthSession->getUser(); if ($user->getId()) { $this->deploymentsFactory->create()->setDeployment('Cache Flush', $user->getUsername() . ' flushed the cache.', $user->getUsername()); } } }
/** * Get user interface locale stored in session data * * @return string */ public function getUserInterfaceLocale() { $interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE; $userData = $this->_authSession->getUser(); if ($userData && $userData->getInterfaceLocale()) { $interfaceLocale = $userData->getInterfaceLocale(); } return $interfaceLocale; }
/** * Log out user and redirect to new admin custom url * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.ExitExpression) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) { return; } $this->_authSession->destroy(); $adminUrl = $this->_backendData->getHomePageUrl(); $this->_response->setRedirect($adminUrl)->sendResponse(); exit(0); }
/** * Log out user and redirect him to new admin custom url * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.ExitExpression) */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) { return; } $this->_authSession->destroy(); $route = $this->_backendData->getAreaFrontName(); $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse(); exit(0); }
/** * Log out user and redirect him to new admin custom url * * @return void * @SuppressWarnings(PHPMD.ExitExpression) */ public function afterCustomUrlChanged() { if (is_null($this->_coreRegistry->registry('custom_admin_path_redirect'))) { return; } $this->_authSession->destroy(); $route = $this->_backendData->getAreaFrontName(); $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse(); exit(0); }
public function change($changeValue, $accountId, $form_key) { $req = new \Praxigento\Accounting\Service\Balance\Request\Change(); $req->setCustomerAccountId($accountId); $req->setChangeValue($changeValue); $userId = $this->_authSession->getUser()->getId(); $req->setAdminUserId($userId); $result = $this->_callBalance->change($req); return $result; }
/** * Test case when module is enabled and user is logged in * * @return void */ public function testReportConcurrentAdminsToNewRelic() { /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */ $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true); $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true); $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock(); $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock); $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true); $this->model->execute($eventObserver); }
/** * Adds New Relic custom parameters per adminhtml request for current admin user, if applicable * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->backendAuthSession->isLoggedIn()) { $user = $this->backendAuthSession->getUser(); $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER_ID, $user->getId()); $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUsername()); $this->newRelicWrapper->addCustomParameter(Config::ADMIN_NAME, $user->getFirstname() . ' ' . $user->getLastname()); } } }
/** * Admin Session prolong functionality * * @param Session $session * @param \Closure $proceed * @return mixed */ public function aroundProlong(Session $session, \Closure $proceed) { if (!$this->sessionsManager->getCurrentSession()->isLoggedInStatus()) { $session->destroy(); $this->addUserLogoutNotification(); return null; } $result = $proceed(); $this->sessionsManager->processProlong(); return $result; }
/** * Test case when module is enabled in config * * @return void */ public function testReportSystemCacheFlushToNewRelic() { /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */ $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true); $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock(); $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock); $userMock->expects($this->once())->method('getId')->willReturn('2'); $this->deploymentsFactory->expects($this->once())->method('create')->willReturn($this->deploymentsModel); $this->deploymentsModel->expects($this->once())->method('setDeployment')->willReturnSelf(); $this->model->execute($eventObserver); }
/** * Test of prolong user action * * @magentoDbIsolation enabled */ public function testProcessProlong() { $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $sessionId = $this->authSession->getSessionId(); $dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - 100); $this->adminSessionsManager->getCurrentSession()->setData('updated_at', $dateInPast)->save(); $this->adminSessionInfo->load($sessionId, 'session_id'); $oldUpdatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->authSession->prolong(); $this->adminSessionInfo->load($sessionId, 'session_id'); $updatedAt = $this->adminSessionInfo->getUpdatedAt(); $this->assertGreaterThan($oldUpdatedAt, $updatedAt); }
/** * Save current admin password to prevent its usage when changed in the future. * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { /* @var $user \Magento\User\Model\User */ $user = $observer->getEvent()->getObject(); if ($user->getId()) { $passwordHash = $user->getPassword(); $passwordLifetime = $this->observerConfig->getAdminPasswordLifetime(); if ($passwordLifetime && $passwordHash && !$user->getForceNewPassword()) { $this->userResource->trackPassword($user, $passwordHash, $passwordLifetime); $this->messageManager->getMessages()->deleteMessageByIdentifier('magento_user_password_expired'); $this->authSession->unsPciAdminUserIsPasswordExpired(); } } }
/** * Reports concurrent admins to the database reporting_users table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->backendAuthSession->isLoggedIn()) { $user = $this->backendAuthSession->getUser(); $jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()]; $modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)]; /** @var \Magento\NewRelicReporting\Model\Users $usersModel */ $usersModel = $this->usersFactory->create(); $usersModel->setData($modelData); $usersModel->save(); } } }
/** * Action that acts as a proxy to the account/index page, when the frontend * oauth controller redirects the admin user back to the backend after * finishing the oauth authorization cycle. * This is a workaround as you cannot redirect directly to a protected * action in the backend end from the front end. The action also handles * passing along any error/success messages. * @return Redirect */ public function execute() { $type = $this->_request->getParam('message_type'); $code = $this->_request->getParam('message_code'); $text = $this->_request->getParam('message_text'); if (!is_null($type) && !is_null($code)) { $this->_backendAuthSession->setData('nosto_message', ['message_type' => $type, 'message_code' => $code, 'message_text' => $text]); } if (($storeId = (int) $this->_request->getParam('store')) !== 0) { return $this->resultRedirectFactory->create()->setPath('*/*/index', ['store' => $storeId]); } else { return $this->resultRedirectFactory->create()->setPath('*/*/index', []); } }
/** * @return void */ public function testAroundProlongSessionIsNotActiveAndIsAjaxRequest() { $result = 'result'; $status = 1; $proceed = function () use($result) { return $result; }; $this->currentSessionMock->expects($this->any())->method('isActive')->willReturn(false); $this->authSessionMock->expects($this->once())->method('destroy'); $this->requestMock->expects($this->once())->method('getParam')->with('isAjax')->willReturn(true); $this->currentSessionMock->expects($this->once())->method('getStatus')->willReturn($status); $this->securityCookieMock->expects($this->once())->method('setLogoutReasonCookie')->with($status)->willReturnSelf(); $this->model->aroundProlong($this->authSessionMock, $proceed); }
/** * Force admin to change password * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { if (!$this->observerConfig->isPasswordChangeForced()) { return; } if (!$this->authSession->isLoggedIn()) { return; } $actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout']; /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getEvent()->getControllerAction(); /** @var \Magento\Framework\App\RequestInterface $request */ $request = $observer->getEvent()->getRequest(); if ($this->authSession->getPciAdminUserIsPasswordExpired()) { if (!in_array($request->getFullActionName(), $actionList)) { if ($this->authorization->isAllowed('Magento_Backend::myaccount')) { $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/')); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true); } else { /* * if admin password is expired and access to 'My Account' page is denied * than we need to do force logout with error message */ $this->authSession->clearStorage(); $this->session->clearStorage(); $this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.')); $controller->getRequest()->setDispatched(false); } } } }