/**
  * Search POSTED user email, send email with request to regenerate password or choose a new one
  *
  * @return mixed
  */
 public function sendrecoverrequestAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return $this->redirect()->toRoute('main');
     }
     $post = $request->getPost()->toArray();
     $inputFilter = new RecoverPasswordFormInputFilter();
     $form = new RecoverPasswordForm();
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $helper = new UsersControllerHelper();
     $helper->setConnection($em->getConnection());
     if ($form->isValid()) {
         $userRecords = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('emailUsername' => $post['email'], 'limit' => 1));
         if (!empty($userRecords) and count($userRecords) == 1) {
             $confirmCode = md5(uniqid());
             $helper->updateConfirmCode($userRecords[0]['id'], $confirmCode);
             $uri = $request->getUri();
             $basePath = sprintf('%s://%s%s', $uri->getScheme(), $uri->getHost(), '');
             $linkRecoverPasswordForm = $basePath . $this->url()->fromRoute('recover-password', array('action' => 'formchangepassword', 'confirmcode' => $confirmCode));
             $appServiceLoader = $this->recoverAppServiceLoader(1);
             $configurations = $appServiceLoader->recoverService('configurations');
             $noReplayMail = isset($configurations['mailnoreply']) ? $configurations['mailnoreply'] : '*****@*****.**';
             $message = $configurations['sitename'] . "\n\n";
             $message .= "E' stata registrata una richiesta di recupero password per il sito in oggetto.\n\n";
             $message .= 'Per scegliere una nuova password, <a href="' . $linkRecoverPasswordForm . '">clicca qui</a>' . "\n\n";
             $message .= "Se non vedi il link, conferma la richiesta copiando e incollando il link sotto riportato sul tuo browser:\n\n";
             $message .= $linkRecoverPasswordForm . "\n\n";
             $message .= 'Non rispondere a questo messaggio' . "\n\n";
             $message .= date("Y") . ' ' . $configurations['sitename'];
             /* Send email with link for password recover */
             $mail = new Mail\Message();
             $mail->setBody($message);
             $mail->setFrom($noReplayMail, $configurations['sitename']);
             $mail->addTo($userRecords[0]['email'], $userRecords[0]['name'] . ' ' . $userRecords[0]['surname']);
             $mail->setSubject('Richiesta recupero password ', $configurations['sitename']);
             $transport = new Mail\Transport\Sendmail($userRecords[0]['email']);
             $transport->send($mail);
             /* Redirect to another page with OK message to avoid double POSTs */
             return $this->redirect()->toRoute('recover-password', array('action' => 'showconfirm', 'confirmcode' => 'passwordRequestSentOk'));
         } else {
             // User not found, invalid request...
         }
     } else {
         // The form is not valid, it can redirect to a confirm message page
     }
     return $this->redirect()->toRoute('main');
 }
Пример #2
0
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new UsersFormInputFilter();
     $form = new UsersForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $helper = new UsersControllerHelper();
     $helper->setConnection($connection);
     $helper->getConnection()->beginTransaction();
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper->setLoggedUser($userDetails);
         $userEmail = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('email' => $inputFilter->email, 'limit' => 1));
         $helper->checkRecordsAreEmpty($userEmail, 'Esiste un utente registrato con questa email');
         $lastInsertId = $helper->insert($inputFilter);
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Inserito nuovo utente " . $inputFilter->name . ' ' . $inputFilter->surname, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Utente inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/users-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'modulename' => $this->params()->fromRoute('modulename'))), 'backToSummaryText' => "Elenco utenti"));
         $helper->getConnection()->commit();
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $ex) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore creazione nuovo utente: " . $inputFilter->name . ' ' . $inputFilter->surname, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore creazione nuovo utente', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati'));
     }
     $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
 }