/** * 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); }
/** * Retrieve current role * * @return string|null */ public function getAclRoleId() { if ($this->_session->hasUser()) { return $this->_session->getUser()->getAclRole(); } return null; }
/** * 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); }
/** * {@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(); }
/** * @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); }
/** * @return bool */ public function hasAvailableResources() { $user = $this->_authSession->getUser(); if ($user && $user->getHasAvailableResources()) { return true; } return false; }
/** * 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; }
/** * 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()); } } }
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; }
/** * 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()); } } }
/** * 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(); } } }
/** * Collection getter with filters populated for testLogoutOtherUserSessions() method * * @param AdminSessionInfo $session * @return ResourceModel\AdminSessionInfo\Collection */ protected function getCollectionForLogoutOtherUserSessions(\Magento\Security\Model\AdminSessionInfo $session) { /** @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection $collection */ $collection = $session->getResourceCollection(); $collection->filterByUser($this->authSession->getUser()->getId(), \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $this->authSession->getSessionId())->filterExpiredSessions(100)->load(); return $collection; }
/** * Get Key pieces for caching block content * * @return array */ public function getCacheKeyInfo() { $cacheKeyInfo = ['admin_top_nav', $this->getActive(), $this->_authSession->getUser()->getId(), $this->_localeResolver->getLocale()]; // Add additional key parameters if needed $newCacheKeyInfo = $this->getAdditionalCacheKeyInfo(); if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) { $cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo); } return $cacheKeyInfo; }
/** * Collapsed or expanded fieldset when page loaded? * * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return bool */ protected function _isCollapseState($element) { if ($element->getExpanded()) { return true; } $extra = $this->_authSession->getUser()->getExtra(); if (isset($extra['configState'][$element->getId()])) { return $extra['configState'][$element->getId()]; } return false; }
/** * Collapsed or expanded fieldset when page loaded? * * @param AbstractElement $element * @return bool */ protected function _isCollapseState($element) { if ($element->getExpanded() || $element->getForm() && $element->getForm()->getElements()->count() === 1) { return true; } $extra = $this->_authSession->getUser()->getExtra(); if (isset($extra['configState'][$element->getId()])) { return $extra['configState'][$element->getId()]; } return $this->isCollapsedDefault; }
/** * Prepare form fields * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return \Magento\Backend\Block\Widget\Form */ protected function _prepareForm() { /** @var $model \Magento\User\Model\User */ $model = $this->_coreRegistry->registry('permissions_user'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('user_'); $baseFieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]); if ($model->getUserId()) { $baseFieldset->addField('user_id', 'hidden', ['name' => 'user_id']); } else { if (!$model->hasData('is_active')) { $model->setIsActive(1); } } $baseFieldset->addField('username', 'text', ['name' => 'username', 'label' => __('User Name'), 'id' => 'username', 'title' => __('User Name'), 'required' => true]); $baseFieldset->addField('firstname', 'text', ['name' => 'firstname', 'label' => __('First Name'), 'id' => 'firstname', 'title' => __('First Name'), 'required' => true]); $baseFieldset->addField('lastname', 'text', ['name' => 'lastname', 'label' => __('Last Name'), 'id' => 'lastname', 'title' => __('Last Name'), 'required' => true]); $baseFieldset->addField('email', 'text', ['name' => 'email', 'label' => __('Email'), 'id' => 'customer_email', 'title' => __('User Email'), 'class' => 'required-entry validate-email', 'required' => true]); $isNewObject = $model->isObjectNew(); if ($isNewObject) { $passwordLabel = __('Password'); } else { $passwordLabel = __('New Password'); } $confirmationLabel = __('Password Confirmation'); $this->_addPasswordFields($baseFieldset, $passwordLabel, $confirmationLabel, $isNewObject); $baseFieldset->addField('interface_locale', 'select', ['name' => 'interface_locale', 'label' => __('Interface Locale'), 'title' => __('Interface Locale'), 'values' => $this->_LocaleLists->getTranslatedOptionLocales(), 'class' => 'select']); if ($this->_authSession->getUser()->getId() != $model->getUserId()) { $baseFieldset->addField('is_active', 'select', ['name' => 'is_active', 'label' => __('This account is'), 'id' => 'is_active', 'title' => __('Account Status'), 'class' => 'input-select', 'options' => ['1' => __('Active'), '0' => __('Inactive')]]); } $baseFieldset->addField('user_roles', 'hidden', ['name' => 'user_roles', 'id' => '_user_roles']); $currentUserVerificationFieldset = $form->addFieldset('current_user_verification_fieldset', ['legend' => __('Current User Identity Verification')]); $currentUserVerificationFieldset->addField(self::CURRENT_USER_PASSWORD_FIELD, 'password', ['name' => self::CURRENT_USER_PASSWORD_FIELD, 'label' => __('Your Password'), 'id' => self::CURRENT_USER_PASSWORD_FIELD, 'title' => __('Your Password'), 'class' => 'input-text validate-current-password required-entry', 'required' => true]); $data = $model->getData(); unset($data['password']); unset($data[self::CURRENT_USER_PASSWORD_FIELD]); $form->setValues($data); $this->setForm($form); return parent::_prepareForm(); }
/** * Observer for controller_front_send_response_before event fired in lib/internal/Magento/Framework/App/Http.php. * * $eventParams = ['request' => $this->_request, 'response' => $this->_response]; * * request => Magento\Framework\App\Request\Http * response => Magento\Framework\Webapi\Rest\Response\Proxy * * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { /* @var $request \Magento\Framework\App\Request\Http */ $request = $observer->getEvent()->getRequest(); $areaCode = $this->areaList->getCodeByFrontName($request->getFrontName()); /** * Stop execution if module is not active * or if the current request falls within excluded areas * or if the current request falls within excluded actions */ if (!$this->helper->isFoggylineSentinelActive() or in_array($areaCode, $this->helper->getExcludeAreas()) or in_array($request->getFullActionName(), $this->helper->getExcludeActions())) { //return $this; } /* @var $log \Foggyline\Sentinel\Model\AccessLog */ $log = $this->log->create(); $log->setRequestId($this->helper->getHttpRequestUniqueId()); if ($this->authSession && $this->authSession->getUser()) { $user = $this->authSession->getUser(); $log->setUserId($user->getId()); $log->setUserUsername($user->getUserName()); $log->setUserEmail($user->getEmail()); $log->setUserName($user->getName()); } $log->setActionName($request->getActionName()); $log->setFullActionName($request->getFullActionName()); $log->setClientIp($request->getClientIp()); $log->setRequestString($request->getRequestString()); $log->setRequestMethod($request->getMethod()); $log->setHttpGetParams($_GET); $log->setHttpPostParams($_POST); $log->setHttpFilesParams($_FILES); $log->setModuleName($request->getModuleName()); $log->setControllerModule($request->getControllerModule()); $log->setArea($areaCode); try { $log->save(); } catch (\Exception $e) { $this->logger->critical($e); } return $this; }
/** * Validate user password * * @param string $password * @return bool */ public function validateUserPassword($password) { $userPasswordHash = $this->_backendAuthSession->getUser()->getPassword(); return $this->_encryptor->validateHash($password, $userPasswordHash); }
/** * {@inheritdoc} */ public function getUserId() { return $this->_adminSession->hasUser() ? (int) $this->_adminSession->getUser()->getId() : null; }
/** * @return \Magento\User\Model\User|null */ public function getUser() { return $this->_authSession->getUser(); }
/** * Create new record * * @return $this */ protected function createNewSession() { $this->adminSessionInfoFactory->create()->setData(['session_id' => $this->authSession->getSessionId(), 'user_id' => $this->authSession->getUser()->getId(), 'ip' => $this->remoteAddress->getRemoteAddress(), 'status' => AdminSessionInfo::LOGGED_IN])->save(); return $this; }