/**
  * Send new password to defined E-Mail.
  */
 protected function send()
 {
     if ($crumbComponent = $this->document->componentManager->getBlockByName('breadCrumbs')) {
         $crumbComponent->addCrumb();
     }
     if ($component = $this->document->componentManager->getBlockByName('textBlockRestorePassword')) {
         $component->disable();
     }
     if (!isset($_POST['u_name'])) {
         $message = $this->translate('ERR_NO_U_NAME');
     } else {
         $uName = $_POST['u_name'];
         if (!($UID = $this->dbh->getScalar('user_users', 'u_id', array('u_name' => $uName)))) {
             $message = $this->translate('ERR_NO_U_NAME');
         } else {
             $password = User::generatePassword();
             $this->dbh->modify(QAL::UPDATE, 'user_users', array('u_password' => password_hash($password, PASSWORD_DEFAULT)), array('u_id' => $UID));
             $user = new User($UID);
             $template = new MailTemplate('user_restore_password', ['user_login' => $uName, 'user_name' => $user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]);
             $mailer = new Mail();
             $mailer->setFrom($this->getConfigValue('mail.from'))->setSubject($template->getSubject())->setText($template->getBody())->setHtmlText($template->getHTMLBody())->addTo($uName);
             $message = $this->translate('MSG_PASSWORD_SENT');
             try {
                 $mailer->send();
             } catch (\Exception $e) {
                 $message = $e->getMessage();
             }
         }
     }
     $this->prepare();
     $messageField = new Field('restore_password_result');
     $messageField->setData($message);
     $this->getData()->addField($messageField);
 }
Exemple #2
0
 /**
  * Save data.
  *
  * @throws SystemException
  */
 protected function saveData()
 {
     $password = $_POST[$this->getTableName()]['u_password'] = User::generatePassword();
     try {
         $result = $this->user->create($_POST[$this->getTableName()]);
         $template = new MailTemplate('user_registration', ['user_login' => $this->user->getValue('u_name'), 'user_name' => $this->user->getValue('u_fullname'), 'user_password' => $password, 'site_url' => E()->getSiteManager()->getCurrentSite()->base, 'site_name' => $this->translate('TXT_SITE_NAME')]);
         $mailer = new Mail();
         $mailer->setFrom($this->getConfigValue('mail.from'));
         $mailer->setSubject($template->getSubject());
         $mailer->setText($template->getBody());
         $mailer->setHtmlText($template->getHTMLBody());
         $mailer->addTo($this->user->getValue('u_name'));
         $mailer->send();
     } catch (\Exception $error) {
         throw new SystemException($error->getMessage(), SystemException::ERR_WARNING);
     }
 }