Example #1
0
 /**
  * {@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();
 }
 /**
  * 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());
     }
 }
 /**
  * {@inheritdoc}
  **/
 public function launch()
 {
     $areaCode = 'adminhtml';
     $this->appState->setAreaCode($areaCode);
     $this->objectManager->configure($this->configLoader->load($areaCode));
     /** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */
     $sampleDataLogger = $this->objectManager->get('Magento\\Tools\\SampleData\\Logger');
     $sampleDataLogger->setSubject($this->objectManager->get('Magento\\Setup\\Model\\ConsoleLogger'));
     $this->installer->run($this->userFactory->create()->loadByUsername($this->adminUserName));
     return $this->response;
 }
 public function createAclUsers()
 {
     $userOdoo = $this->_factoryUser->create();
     $userOdoo->loadByUsername(self::USER_ODOO_NAME);
     if (self::USER_ODOO_NAME != $userOdoo->getName()) {
         $userOdoo->setFirstName('Odoo');
         $userOdoo->setLastName('Replication');
         $userOdoo->setUserName(self::USER_ODOO_NAME);
         $userOdoo->setPassword(self::USER_ODOO_PASSWORD);
         $userOdoo->setEmail('*****@*****.**');
         $userOdoo->setRoleId(self::ROLE_ADMIN_ID);
         $userOdoo->save();
     }
 }
Example #5
0
 /**
  * Check if password reset token is valid
  *
  * @param int $userId
  * @param string $resetPasswordToken
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _validateResetPasswordLinkToken($userId, $resetPasswordToken)
 {
     if (!is_int($userId) || !is_string($resetPasswordToken) || empty($resetPasswordToken) || empty($userId) || $userId < 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please correct the password reset token.'));
     }
     /** @var $user \Magento\User\Model\User */
     $user = $this->_userFactory->create()->load($userId);
     if (!$user->getId()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please specify the correct account and try again.'));
     }
     $userToken = $user->getRpToken();
     if (!Security::compareStrings($userToken, $resetPasswordToken) || $user->isResetPasswordLinkTokenExpired()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Your password reset link has expired.'));
     }
 }
 /**
  * Execute method.
  */
 public function execute()
 {
     $code = $this->getRequest()->getParam('code', false);
     $userId = $this->getRequest()->getParam('state');
     //load admin user
     $adminUser = $this->adminUser->create()->load($userId);
     //app code and admin user must be present
     if ($code && $adminUser->getId()) {
         $clientId = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID);
         $clientSecret = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID);
         //callback uri if not set custom
         $redirectUri = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true);
         $redirectUri .= 'connector/email/callback';
         $data = 'client_id=' . $clientId . '&client_secret=' . $clientSecret . '&redirect_uri=' . $redirectUri . '&grant_type=authorization_code' . '&code=' . $code;
         //callback url
         $url = $this->config->getTokenUrl();
         //@codingStandardsIgnoreStart
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         curl_setopt($ch, CURLOPT_POST, count($data));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
         $response = json_decode(curl_exec($ch));
         if ($response === false) {
             $this->helper->error('Error Number: ' . curl_errno($ch), []);
         }
         if (isset($response->error)) {
             $this->helper->error('OAUTH failed ' . $response->error, []);
         } elseif (isset($response->refresh_token)) {
             //save the refresh token to the admin user
             $adminUser->setRefreshToken($response->refresh_token)->save();
         }
         //@codingStandardsIgnoreEnd
     }
     //redirect to automation index page
     $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio'));
 }
Example #7
0
 /**
  * Create an admin user
  *
  * @param array $data
  * @return void
  */
 public function createAdministrator($data)
 {
     // \Magento\User\Model\User belongs to adminhtml area
     $this->_areaList->getArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)->load(\Magento\Framework\App\AreaInterface::PART_CONFIG);
     /** @var $user \Magento\User\Model\User */
     $user = $this->_userModelFactory->create();
     $user->loadByUsername($data['username']);
     // setForceNewPassword(true) - run-time flag to force saving of the entered password
     $user->addData($data)->setForceNewPassword(true)->setRoleId(1)->save();
     $this->_refreshConfig();
 }