Example #1
0
 /**
  * @param mixed $expanded
  * @param int $expected
  * @dataProvider isCollapseStateDataProvider
  */
 public function testIsCollapseState($expanded, $expected)
 {
     $this->_user->setExtra(['configState' => []]);
     $this->_element->setGroup(isset($expanded) ? ['expanded' => $expanded] : []);
     $html = $this->_model->render($this->_element);
     $this->assertContains('<input id="' . $this->_element->getHtmlId() . '-state" name="config_state[' . $this->_element->getId() . ']" type="hidden" value="' . $expected . '" />', $html);
 }
Example #2
0
 /**
  * @param \Magento\User\Model\User $model
  * @param array $data
  * @return void
  */
 protected function redirectToEdit(\Magento\User\Model\User $model, array $data)
 {
     $this->_getSession()->setUserData($data);
     $arguments = $model->getId() ? ['user_id' => $model->getId()] : [];
     $arguments = array_merge($arguments, ['_current' => true, 'active_tab' => '']);
     $this->_redirect('adminhtml/*/edit', $arguments);
 }
Example #3
0
 public function testToHtmlPasswordFieldsExistingEntry()
 {
     $this->_user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
     $actualHtml = $this->_block->toHtml();
     $this->assertSelectCount('input.required-entry[type="password"]', 0, $actualHtml, 'All password fields have to be optional.');
     $this->assertSelectCount('input.validate-admin-password[type="password"][name="password"]', 1, $actualHtml);
     $this->assertSelectCount('input.validate-cpassword[type="password"][name="password_confirmation"]', 1, $actualHtml);
 }
Example #4
0
 public function testToHtmlPasswordFieldsExistingEntry()
 {
     $this->_user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
     $actualHtml = $this->_block->toHtml();
     $this->assertSelectCount('input.required-entry[type="password"]', 1, $actualHtml, 'There should be 1 required password entry: current user password.');
     $this->assertSelectCount('input.validate-admin-password[type="password"][name="password"]', 1, $actualHtml);
     $this->assertSelectCount('input.validate-cpassword[type="password"][name="password_confirmation"]', 1, $actualHtml);
     $this->assertSelectCount('input.validate-current-password[type="password"][name="' . Main::CURRENT_USER_PASSWORD_FIELD . '"]', 1, $actualHtml);
 }
 /**
  * @magentoDataFixture Magento/User/_files/user_with_role.php
  */
 public function testCreateAdminAccessToken()
 {
     $adminUserNameFromFixture = 'adminUser';
     $accessToken = $this->tokenService->createAdminAccessToken($adminUserNameFromFixture, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
     $adminUserId = $this->userModel->loadByUsername($adminUserNameFromFixture)->getId();
     /** @var $token TokenModel */
     $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken();
     $this->assertEquals($accessToken, $token);
 }
 /**
  * @magentoApiDataFixture Magento/User/_files/user_with_role.php
  */
 public function testCreateAdminAccessToken()
 {
     $adminUserNameFromFixture = 'adminUser';
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH_ADMIN_TOKEN, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST]];
     $requestData = ['username' => $adminUserNameFromFixture, 'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD];
     $accessToken = $this->_webApiCall($serviceInfo, $requestData);
     $adminUserId = $this->userModel->loadByUsername($adminUserNameFromFixture)->getId();
     /** @var $token TokenModel */
     $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken();
     $this->assertEquals($accessToken, $token);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validate($username, $password);
     $this->userModel->login($username, $password);
     if (!$this->userModel->getId()) {
         /*
          * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
          * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
          * Need to make sure that this is refactored once exception handling is updated in Auth Model.
          */
         throw new AuthenticationException(__('You did not sign in correctly or your account is temporarily disabled.'));
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
 /**
  * Make sure provided token is valid and belongs to the specified user.
  *
  * @param string $username
  * @param string $accessToken
  */
 private function assertToken($username, $accessToken)
 {
     $adminUserId = $this->userModel->loadByUsername($username)->getId();
     /** @var $token TokenModel */
     $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken();
     $this->assertEquals($accessToken, $token);
 }
Example #9
0
 public function testGetSetHasAvailableResources()
 {
     $this->_model->setHasAvailableResources(true);
     $this->assertTrue($this->_model->hasAvailableResources());
     $this->_model->setHasAvailableResources(false);
     $this->assertFalse($this->_model->hasAvailableResources());
 }
Example #10
0
 /**
  * @return void
  */
 public function testIsResetPasswordLinkTokenExpiredIsNotExpiredToken()
 {
     $this->model->setRpToken('1');
     $this->model->setRpTokenCreatedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
     $this->userDataMock->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(1);
     $this->assertFalse($this->model->isResetPasswordLinkTokenExpired());
 }
Example #11
0
 public function testSaveExtraFilledId()
 {
     $uid = 123;
     $this->userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid);
     $this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->dbAdapterMock);
     $this->dbAdapterMock->expects($this->once())->method('update');
     $this->assertInstanceOf('Magento\\User\\Model\\ResourceModel\\User', $this->model->saveExtra($this->userMock, [1, 2, 3]));
 }
Example #12
0
    public function testBeforeSave()
    {
        $this->userMock->expects($this->once())->method('isObjectNew')->willReturn(true);

        $this->assertInstanceOf(
            '\Magento\User\Model\ResourceModel\User',
            $this->invokeMethod($this->model, '_beforeSave', [$this->userMock])
        );
    }
Example #13
0
 public function testVerifyIdentityNoAssignedRoles()
 {
     $password = '******';
     $this->_encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->_model->getPassword())->will($this->returnValue(true));
     $this->_model->setIsActive(true);
     $this->_resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false));
     $this->setExpectedException('Magento\\Framework\\Exception\\AuthenticationException', 'Access denied.');
     $this->_model->verifyIdentity($password);
 }
Example #14
0
 /**
  * Run installation in context of the specified admin user
  *
  * @param \Magento\User\Model\User $adminUser
  * @throws \Exception
  *
  * @return void
  */
 public function run(\Magento\User\Model\User $adminUser)
 {
     set_time_limit(3600);
     if (!$adminUser || !$adminUser->getId()) {
         throw new \Exception('Invalid admin user provided');
     }
     $this->session->setUser($adminUser);
     $this->deploy->run();
     $resources = $this->initResources();
     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();
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validateCredentials($username, $password);
     try {
         $this->userModel->login($username, $password);
         if (!$this->userModel->getId()) {
             /*
              * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
              * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
              * Need to make sure that this is refactored once exception handling is updated in Auth Model.
              */
             throw new AuthenticationException('Please correct the user name or password.');
         }
     } catch (\Magento\Backend\Model\Auth\Exception $e) {
         throw new AuthenticationException($e->getMessage(), [], $e);
     } catch (\Magento\Framework\Model\Exception $e) {
         throw new LocalizedException($e->getMessage(), [], $e);
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
Example #16
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = array('password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**');
     $testedMessage = 'The account has been saved.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Locale\\Validator'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
Example #17
0
 public function testCheckPasswordChangeValid()
 {
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(true);
     $newPassword = "******";
     $newPasswordHash = "new password hash";
     $oldPassword = "******";
     $this->model->setPassword($newPassword)->setId(1)->setOrigData('password', $oldPassword);
     $this->encryptorMock->expects($this->once())->method('isValidHash')->with($newPassword, $oldPassword)->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->with($newPassword, false)->willReturn($newPasswordHash);
     $this->resourceMock->expects($this->once())->method('getOldPasswords')->willReturn(['hash1', 'hash2']);
     $result = $this->model->validate();
     $this->assertTrue($result);
 }
 /**
  * @return void
  */
 public function testLogoutOtherUserSessions()
 {
     $useId = 1;
     $sessionLifetime = 100;
     $sessionId = 50;
     $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock);
     $this->authSessionMock->expects($this->once())->method('getUser')->willReturn($this->userMock);
     $this->authSessionMock->expects($this->once())->method('getSessionId')->willReturn($sessionId);
     $this->userMock->expects($this->once())->method('getId')->willReturn($useId);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')->with($useId, \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $sessionId)->willReturnSelf();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->willReturn($sessionLifetime);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterExpiredSessions')->with($sessionLifetime)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('loadData')->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('setDataToAll')->with($this->equalTo('status'), \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('save');
     $this->model->logoutOtherUserSessions();
 }
 /**
  * Test for performIdentityCheck method
  *
  * @param bool $verifyIdentityResult
  * @param bool $lockExpires
  * @dataProvider dataProviderPerformIdentityCheck
  */
 public function testPerformIdentityCheck($verifyIdentityResult, $lockExpires)
 {
     $password = '******';
     $userName = '******';
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->model->getPassword())->willReturn($verifyIdentityResult);
     $this->model->setIsActive(true);
     $this->resourceMock->expects($this->any())->method('hasAssigned2Role')->willReturn(true);
     $this->model->setUserName($userName);
     $this->model->setLockExpires($lockExpires);
     $this->eventManagerMock->expects($this->any())->method('dispatch')->with('admin_user_authenticate_after', ['username' => $userName, 'password' => $password, 'user' => $this->model, 'result' => $verifyIdentityResult])->willReturnSelf();
     if ($lockExpires) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\State\\UserLockedException', __('Your account is temporarily disabled.'));
     }
     if (!$verifyIdentityResult) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\AuthenticationException', __('You have entered an invalid password for current user.'));
     }
     $this->model->performIdentityCheck($password);
 }
Example #20
0
 /**
  * @param string $actionName
  * @return \Magento\Integration\Controller\Adminhtml\Integration
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _createIntegrationController($actionName)
 {
     // Mock Layout passed into constructor
     $this->_viewMock = $this->getMockBuilder('Magento\\Framework\\App\\ViewInterface')->getMock();
     $this->_layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
     $this->_layoutMergeMock = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock();
     $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnValue($this->_layoutMergeMock));
     $testElement = new \Magento\Framework\Simplexml\Element('<test>test</test>');
     $this->_layoutMock->expects($this->any())->method('getNode')->will($this->returnValue($testElement));
     // for _setActiveMenu
     $this->_viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->_layoutMock));
     $blockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->getMock();
     $menuMock = $this->getMock('Magento\\Backend\\Model\\Menu', [], [$this->getMock('Psr\\Log\\LoggerInterface')]);
     $loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $loggerMock->expects($this->any())->method('critical')->will($this->returnSelf());
     $menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
     $blockMock->expects($this->any())->method('getMenuModel')->will($this->returnValue($menuMock));
     $this->_layoutMock->expects($this->any())->method('getMessagesBlock')->will($this->returnValue($blockMock));
     $this->_layoutMock->expects($this->any())->method('getBlock')->will($this->returnValue($blockMock));
     $this->_viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->viewConfigMock);
     $this->viewConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock);
     $this->_escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $this->resultRedirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->_authMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->willReturn($this->_userMock);
     $this->_backendSessionMock->expects($this->any())->method('getIntegrationData')->willReturn(['all_resources' => 1]);
     $contextParameters = ['view' => $this->_viewMock, 'objectManager' => $this->_objectManagerMock, 'session' => $this->_backendSessionMock, 'translator' => $this->_translateModelMock, 'request' => $this->_requestMock, 'response' => $this->_responseMock, 'messageManager' => $this->_messageManager, 'resultRedirectFactory' => $this->resultRedirectFactory, 'resultFactory' => $this->resultFactory, 'auth' => $this->_authMock, 'eventManager' => $this->_eventManagerMock];
     $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject('Magento\\Backend\\App\\Action\\Context', $contextParameters);
     $integrationCollection = $this->getMockBuilder('\\Magento\\Integration\\Model\\ResourceModel\\Integration\\Collection')->disableOriginalConstructor()->setMethods(['addUnsecureUrlsFilter', 'getSize'])->getMock();
     $integrationCollection->expects($this->any())->method('addUnsecureUrlsFilter')->will($this->returnValue($integrationCollection));
     $integrationCollection->expects($this->any())->method('getSize')->will($this->returnValue(0));
     $subControllerParams = ['context' => $this->_backendActionCtxMock, 'integrationService' => $this->_integrationSvcMock, 'oauthService' => $this->_oauthSvcMock, 'registry' => $this->_registryMock, 'logger' => $loggerMock, 'integrationData' => $this->_integrationHelperMock, 'escaper' => $this->_escaper, 'integrationCollection' => $integrationCollection];
     /** Create IntegrationController to test */
     $controller = $this->_objectManagerHelper->getObject('\\Magento\\Integration\\Controller\\Adminhtml\\Integration\\' . $actionName, $subControllerParams);
     if ($actionName == 'Save') {
         $reflection = new \ReflectionClass(get_class($controller));
         $reflectionProperty = $reflection->getProperty('securityCookie');
         $reflectionProperty->setAccessible(true);
         $reflectionProperty->setValue($controller, $this->securityCookieMock);
     }
     return $controller;
 }
Example #21
0
 public function testSendPasswordResetConfirmationEmail()
 {
     $storeId = 0;
     $email = '*****@*****.**';
     $firstName = 'Foo';
     $lastName = 'Bar';
     $this->_model->setEmail($email);
     $this->_model->setFirstname($firstName);
     $this->_model->setLastname($lastName);
     $this->_configMock->expects($this->at(0))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE)->will($this->returnValue('templateId'));
     $this->_configMock->expects($this->at(1))->method('getValue')->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY)->will($this->returnValue('sender'));
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(array('user' => $this->_model, 'store' => $this->_storetMock))->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('addTo')->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName))->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setFrom')->with('sender')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with('templateId')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transportMock));
     $this->_transportMock->expects($this->once())->method('sendMessage');
     $this->_storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($this->_storetMock));
     $this->assertInstanceOf('\\Magento\\User\\Model\\User', $this->_model->sendPasswordResetConfirmationEmail());
 }
Example #22
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = ['password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**', \Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password'];
     $testedMessage = __('You saved the account.');
     $this->authSessionMock->expects($this->any())->method('getUser')->willReturn($this->userMock);
     $this->userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->willReturn(true);
     $this->managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->willReturn($this->authSessionMock);
     $this->objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->willReturn($this->userMock);
     $this->objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Validator\\Locale'))->willReturn($this->validatorMock);
     $this->objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->willReturn($this->managerMock);
     $this->userMock->expects($this->once())->method('save');
     $this->userMock->expects($this->once())->method('verifyIdentity')->willReturn(true);
     $this->userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->userMock->setUserId($userId);
     $this->requestMock->setParams($requestParams);
     $this->controller->executeInternal();
 }
Example #23
0
 /**
  * Check is user logged in and permissions
  *
  * @param \Magento\User\Model\User|null $user
  * @return bool
  */
 protected function _checkUserAccess($user = null)
 {
     if ($user && !$user->getId()) {
         $this->addMessage('error', 'Invalid user name or password');
         $this->controller()->setAction('login');
     } elseif ($this->getUserId() || $user && $user->getId()) {
         if (\Mage::getSingleton('Magento\\Framework\\AuthorizationInterface')->isAllowed('Magento_Adminhtml::all')) {
             return true;
         } else {
             $this->logout();
             $this->addMessage('error', 'Access Denied', true);
             $this->controller()->setAction('login');
         }
     }
     return false;
 }
Example #24
0
 /**
  * Create role for provided user of provided type
  *
  * @param int $parentId
  * @param ModelUser $user
  * @return void
  */
 protected function _createUserRole($parentId, ModelUser $user)
 {
     if ($parentId > 0) {
         /** @var \Magento\Authorization\Model\Role $parentRole */
         $parentRole = $this->_roleFactory->create()->load($parentId);
     } else {
         $role = new \Magento\Framework\Object();
         $role->setTreeLevel(0);
     }
     if ($parentRole->getId()) {
         $data = new \Magento\Framework\Object(array('parent_id' => $parentRole->getId(), 'tree_level' => $parentRole->getTreeLevel() + 1, 'sort_order' => 0, 'role_type' => RoleUser::ROLE_TYPE, 'user_id' => $user->getId(), 'user_type' => UserContextInterface::USER_TYPE_ADMIN, 'role_name' => $user->getFirstname()));
         $insertData = $this->_prepareDataForTable($data, $this->getTable('authorization_role'));
         $this->_getWriteAdapter()->insert($this->getTable('authorization_role'), $insertData);
         $this->_aclCache->clean();
     }
 }
Example #25
0
 /**
  * Set shipper details into request
  * @param \Magento\Shipping\Model\Shipment\Request $request
  * @param \Magento\User\Model\User $storeAdmin
  * @param \Magento\Framework\DataObject $store
  * @param $shipmentStoreId
  * @param $regionCode
  * @param $originStreet
  * @return void
  */
 protected function setShipperDetails(Request $request, User $storeAdmin, DataObject $store, $shipmentStoreId, $regionCode, $originStreet)
 {
     $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, ScopeInterface::SCOPE_STORE, $shipmentStoreId);
     $request->setShipperContactPersonName($storeAdmin->getName());
     $request->setShipperContactPersonFirstName($storeAdmin->getFirstname());
     $request->setShipperContactPersonLastName($storeAdmin->getLastname());
     $request->setShipperContactCompanyName($store->getName());
     $request->setShipperContactPhoneNumber($store->getPhone());
     $request->setShipperEmail($storeAdmin->getEmail());
     $request->setShipperAddressStreet(trim($originStreet . ' ' . $originStreet2));
     $request->setShipperAddressStreet1($originStreet);
     $request->setShipperAddressStreet2($originStreet2);
     $request->setShipperAddressCity($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_CITY, ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     $request->setShipperAddressStateOrProvinceCode($regionCode);
     $request->setShipperAddressPostalCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ZIP, ScopeInterface::SCOPE_STORE, $shipmentStoreId));
     $request->setShipperAddressCountryCode($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, ScopeInterface::SCOPE_STORE, $shipmentStoreId));
 }
Example #26
0
 /**
  * Here we check for a locked user
  *
  * @magentoDataFixture Magento/User/_files/locked_users.php
  * @expectedException \Magento\Framework\Exception\State\UserLockedException
  * @expectedExceptionMessage You did not sign in correctly or your account is temporarily disabled.
  */
 public function testPerformIdentityCheckLockExpires()
 {
     $this->_model->loadByUsername('adminUser2');
     $this->_model->performIdentityCheck(\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
 }
Example #27
0
 /**
  * Remember a password hash for further usage
  *
  * @param ModelUser $user
  * @param string $passwordHash
  * @param int $lifetime
  * @return void
  */
 public function trackPassword($user, $passwordHash, $lifetime)
 {
     $now = time();
     $this->getConnection()->insert($this->getTable('admin_passwords'), ['user_id' => $user->getId(), 'password_hash' => $passwordHash, 'expires' => $now + $lifetime, 'last_updated' => $now]);
 }
Example #28
0
 /**
  * Update locking information for the user
  *
  * @param \Magento\User\Model\User $user
  * @return void
  */
 private function _updateLockingInformation($user)
 {
     $now = new \DateTime();
     $lockThreshold = $this->observerConfig->getAdminLockThreshold();
     $maxFailures = $this->observerConfig->getMaxFailures();
     if (!($lockThreshold && $maxFailures)) {
         return;
     }
     $failuresNum = (int) $user->getFailuresNum() + 1;
     /** @noinspection PhpAssignmentInConditionInspection */
     if ($firstFailureDate = $user->getFirstFailure()) {
         $firstFailureDate = new \DateTime($firstFailureDate);
     }
     $newFirstFailureDate = false;
     $updateLockExpires = false;
     $lockThreshInterval = new \DateInterval('PT' . $lockThreshold . 'S');
     // set first failure date when this is first failure or last first failure expired
     if (1 === $failuresNum || !$firstFailureDate || $now->diff($firstFailureDate) > $lockThreshInterval) {
         $newFirstFailureDate = $now;
         // otherwise lock user
     } elseif ($failuresNum >= $maxFailures) {
         $updateLockExpires = $now->add($lockThreshInterval);
     }
     $this->userResource->updateFailure($user, $updateLockExpires, $newFirstFailureDate);
 }
Example #29
0
 /**
  * @param $id
  * @return \Magento\User\Model\User
  */
 public function getAdminUser($id)
 {
     return $this->adminUser->load($id);
 }
 /**
  * Retrieve the admin user's information.
  *
  * @return array
  */
 private function getExpectedExtensionAttributes()
 {
     $this->user->load(1);
     return ['firstname' => $this->user->getFirstname(), 'lastname' => $this->user->getLastname(), 'email' => $this->user->getEmail()];
 }