public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $helper = new UsersControllerHelper();
     $settoriRecords = $helper->recoverWrapperRecordsById(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $usersRecords = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('adminAccess' => 1));
     $toReturn = array();
     foreach ($usersRecords as $record) {
         if (isset($record['id']) and isset($record['surname']) and isset($record['name'])) {
             $toReturn[$record['id']] = $record['surname'] . ' ' . $record['name'];
         }
     }
     $usersRecordsForDropDown = $toReturn;
     $form = new UsersSettoriForm();
     $form->addResponsabile($usersRecordsForDropDown);
     if ($settoriRecords) {
         $form->setData($settoriRecords[0]);
         $submitButtonValue = 'Modifica';
         $formTitle = 'Modifica settore utente';
         $formAction = $this->url()->fromRoute('admin/users-settori-update', array('lang' => $lang));
     } else {
         $formTitle = 'Nuovo settore utente';
         $submitButtonValue = 'Inserisci';
         $formAction = $this->url()->fromRoute('admin/users-settori-insert', array('lang' => $lang));
     }
     $this->layout()->setVariables(array('formTitle' => $formTitle, 'formDescription' => 'Compila i dati relativi al settore utenti', 'form' => $form, 'formAction' => $formAction, 'submitButtonValue' => $submitButtonValue, 'formBreadCrumbCategory' => array(array('label' => 'Utenti', 'href' => $this->url()->fromRoute('admin/users-summary', array('lang' => $lang)), 'title' => 'Elenco utenti'), array('label' => 'Settori', 'href' => $this->url()->fromRoute('admin/users-settori-summary', array('lang' => $lang)), 'title' => 'Elenco settori utenti')), 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 /**
  * 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');
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $lang = $this->params()->fromRoute('lang');
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     $helper = new UsersControllerHelper();
     $wrapper = $helper->recoverWrapperRecordsPaginator(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array('orderBy' => 'settore.id DESC'), $page, $perPage);
     $paginator = $wrapper->getPaginator();
     $paginatorRecords = $wrapper->setupRecords();
     $this->layout()->setVariables(array('tableTitle' => 'Settori utenti', 'tableDescription' => $paginator->getTotalItemCount() . ' settori utenti', 'paginator' => $paginator, 'columns' => array("Nome", "Responsabile", "&nbsp;", "&nbsp;"), 'records' => $this->formatRecords($paginatorRecords), 'paginator' => $paginator, 'dataTableActiveTitle' => 'Settori', 'formBreadCrumbCategory' => array(array('label' => 'Utenti', 'href' => $this->url()->fromRoute('admin/users-summary', array('lang' => $lang)), 'title' => 'Elenco utenti')), 'templatePartial' => self::summaryTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     $userDetails = $this->layout()->getVariable('userDetails');
     $userRole = isset($userDetails->role) ? $userDetails->role : '';
     $helper = new UsersControllerHelper();
     $wrapper = $helper->recoverWrapperRecordsPaginator(new UsersGetterWrapper(new UsersGetter($em)), array('excludeRoleName' => $userRole == 'WebMaster' ? null : 'WebMaster', 'orderBy' => 'u.id DESC'), $page, $perPage);
     $paginator = $wrapper->getPaginator();
     $paginatorCount = $paginator->getTotalItemCount();
     $paginatorRecords = $wrapper->setupRecords();
     $this->layout()->setVariables(array('tableTitle' => 'Utenti', 'tableDescription' => $paginatorCount . ' utenti in archivio', 'paginator' => $paginator, 'columns' => array("Nome e cognome", "Email", "Ruolo", "Settore", "Ultima modifica", "&nbsp;", "&nbsp;"), 'records' => $this->formatRecords($paginatorRecords), 'paginator' => $paginator, 'total_item_count' => $paginatorCount, 'templatePartial' => self::summaryTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 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');
 }
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $helper = new UsersControllerHelper();
         $usersRespProcRecords = $helper->recoverWrapperRecords(new UsersRespProcGetterWrapper(new UsersRespProcGetter($em)), array('orderBy' => 'u.surname'));
         $idsToExclude = $helper->gatherIdsFromRecordset($usersRespProcRecords);
         $userRecords = $helper->recoverWrapperRecords(new UsersGetterWrapper(new UsersGetter($em)), array('fields' => 'u.id, u.name, u.surname', 'adminAccess' => 1, 'excludeId' => $idsToExclude, 'orderBy' => 'u.surname'));
         if (!empty($userRecords)) {
             $usersForDropDown = $helper->formatForDropwdown($userRecords, 'id', 'name');
         } else {
             $usersForDropDown = array();
         }
         $form = new UsersRespProcForm();
         $form->addUsers($usersForDropDown);
         $this->layout()->setVariables(array('form' => $form, 'usersRespProc' => $usersRespProcRecords, 'usersForDropDown' => $usersForDropDown, 'formDataCommonPath' => 'backend/templates/common/', 'formBreadCrumbCategory' => array(array('href' => $this->url()->fromRoute('admin/users-responsabili-procedimento', array('lang' => $this->params()->fromRoute('lang'))), 'label' => 'Atti di concessione', 'title' => 'Elenco atti di concessione')), 'formBreadCrumbTitle' => 'Responsabili procedimento', 'templatePartial' => 'users/resp-proc-management.phtml'));
     } catch (\Exception $e) {
     }
     $this->layout()->setTemplate($mainLayout);
 }
Example #7
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $userDetails = $this->layout()->getVariable('userDetails');
     /* Check user ID and UPDATE permission */
     if ($userDetails->id != $id and !$userDetails->acl->hasResource('users_update') and $id != '') {
         return $this->redirect()->toRoute('admin/not-authorized', array('lang' => 'it'));
     }
     /* Check user ID and INSERT permission */
     if ($id == '' and !$userDetails->acl->hasResource('users_add')) {
         return $this->redirect()->toRoute('admin/not-authorized', array('lang' => 'it'));
     }
     $helper = new UsersControllerHelper();
     $records = $helper->recoverWrapperRecordsById(new UsersGetterWrapper(new UsersGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $form = new UsersForm();
     if (!empty($records)) {
         $form->addPasswords();
     } else {
         $form->addPasswordsMandatory();
     }
     /* Check Roles permission */
     if ($userDetails->acl->hasResource('users_roles_update')) {
         $rolesRecords = $helper->recoverWrapperRecords(new UsersRolesGetterWrapper(new UsersRolesGetter($em)), array());
         $rolesRecordsForDropDown = $helper->formatForDropwdown($rolesRecords, 'id', 'name');
         $form->addRoles($rolesRecordsForDropDown);
     }
     /* Check Settori permission */
     if ($userDetails->acl->hasResource('users_settori_update')) {
         $settoriRecords = $helper->recoverWrapperRecords(new UsersSettoriGetterWrapper(new UsersSettoriGetter($em)), array());
         $settoriRecordsForDropDown = $helper->formatForDropwdown($settoriRecords, 'id', 'nome');
         $form->addSettori($settoriRecordsForDropDown);
     }
     if (!empty($records)) {
         $formAction = $this->url()->fromRoute('admin/users-update', array('lang' => $lang));
         $formTitle = 'Modifica utente';
         $formDescription = 'Modifica dati utente. Per creare una <strong>password sicura</strong>, scegliere una string lunga almeno 8 caratteri e che contenga caratteri speciali, lettere maiuscole e\\o minuscole e numeri.';
         $form->setData($records[0]);
     } else {
         $formAction = $this->url()->fromRoute('admin/users-insert', array('lang' => $lang));
         $formTitle = 'Nuovo utente';
         $formDescription = 'Creazione nuovo utente. Per creare una <strong>password sicura</strong>, scegliere una string lunga almeno 8 caratteri e che contenga caratteri speciali, lettere maiuscole e\\o minuscole e numeri.';
     }
     $this->layout()->setVariables(array('form' => $form, 'formTitle' => $formTitle, 'formDescription' => $formDescription, 'formAction' => $formAction, 'formBreadCrumbCategory' => 'Utenti', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/users-summary', array('lang' => $this->params()->fromRoute('lang'))), 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 /**
  * @expectedException \Exception
  */
 public function testVerifyPasswordThrowsException()
 {
     $this->helper->verifyPassword('mypass1', 'mypass2', 'My error message');
 }