/**
  * @static
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocatorInterface
  * @return AuthenticationManager
  */
 public static function getInstance(ServiceLocatorInterface $serviceLocatorInterface)
 {
     if (self::$instance == null) {
         self::$instance = new AuthenticationManager();
         self::$instance->setServiceLocator($serviceLocatorInterface);
     }
     return self::$instance;
 }
 public function loginAction()
 {
     $user = ApplicationManager::getInstance($this->getServiceLocator())->getCurrentUser();
     if ($user) {
         return $this->redirect()->toRoute('home');
     }
     $request = $this->getRequest();
     $form = new LoginForm();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $identity = $data['email'];
             $password = $data['password'];
             $result = AuthenticationManager::getInstance($this->getServiceLocator())->authenticate($identity, $password);
             if (in_array($result->getCode(), array(Result::FAILURE_IDENTITY_NOT_FOUND, Result::FAILURE_CREDENTIAL_INVALID))) {
                 $form->setMessages(array('email' => array('Нeправильный Email или пароль')));
             }
             if ($result->isValid()) {
                 return $this->redirect()->toRoute('dashboard');
             }
         } else {
             $form->setMessages(array('email' => array('Нeправильный Email или пароль')));
         }
     }
     $viewModel = new ViewModel(array('form' => $form));
     $viewModel->setTemplate('layout/login-layout');
     $viewModel->setTerminal(true);
     return $viewModel;
 }
Example #3
0
 public function onAppDispatch(MvcEvent $e)
 {
     $matches = $e->getRouteMatch();
     if ($matches) {
         $route = $matches->getMatchedRouteName();
         if ($route != 'login' && $matches != 'logout') {
             try {
                 $user = ApplicationManager::getInstance($e->getApplication()->getServiceManager())->getCurrentUser();
             } catch (\Exception $ex) {
                 $user = null;
             }
             if (!$user) {
                 $this->redirect('login', $e);
             } else {
                 if ($user->getRole()->getId() == 2 && $route == 'users') {
                     $this->redirect('dashboard', $e);
                 }
             }
         }
     } else {
         $this->redirect('login', $e);
     }
 }
 /**
  * @return \Application\Entity\User
  */
 public function __invoke()
 {
     return \Application\Manager\ApplicationManager::getInstance($this->serviceLocator)->getCurrentUser();
 }
 public function addAction()
 {
     $config = $this->getServiceLocator()->get('config');
     $applicationManager = ApplicationManager::getInstance($this->getServiceLocator());
     $form = new ClientsForm(array('services' => $applicationManager->prepareFormServices(), 'clinics' => $applicationManager->prepareFormClinics(), 'doctors' => $applicationManager->prepareFormDoctors(), 'countries' => $applicationManager->prepareFormCountries()));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(strtotime($data['dos']));
             $data['dos'] = $dateTime;
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(strtotime($data['nextContactDate']));
             $data['nextContactDate'] = $dateTime;
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(time());
             $now = $dateTime;
             if (!empty($data['newClinic'])) {
                 $newClinic = new Clinic();
                 $newClinic->setName($data['newClinic']);
                 ClinicDAO::getInstance($this->getServiceLocator())->save($newClinic);
                 $data['clinic'] = $newClinic->getId();
             }
             if (!empty($data['newDoctor'])) {
                 $newDoctor = new Doctor();
                 $newDoctor->setName($data['newDoctor']);
                 DoctorDAO::getInstance($this->getServiceLocator())->save($newDoctor);
                 $data['doctor'] = $newDoctor->getId();
             }
             if (!empty($data['newCountry'])) {
                 $newCountry = new Country();
                 $newCountry->setName($data['newCountry']);
                 CountryDAO::getInstance($this->getServiceLocator())->save($newCountry);
                 $data['country'] = $newDoctor->getId();
             }
             if (!empty($post['attachments'])) {
                 foreach ($post['attachments'] as $attach) {
                     if (!empty($attach['name'])) {
                         $attach['name'] = str_replace(' ', '_', $attach['name']);
                         move_uploaded_file($attach['tmp_name'], $config['app']['uploads_path'] . $attach['name']);
                         $attachmentNames[] = 'uploads/' . $attach['name'];
                     }
                 }
             }
             if (!empty($post['conclusions'])) {
                 foreach ($post['conclusions'] as $conclusion) {
                     if (!empty($conclusion['name'])) {
                         $conclusion['name'] = str_replace(' ', '_', $conclusion['name']);
                         move_uploaded_file($conclusion['tmp_name'], $config['app']['uploads_path'] . $conclusion['name']);
                         $conclusionNames[] = 'uploads/' . $conclusion['name'];
                     }
                 }
             } else {
                 $conclusionNames = array();
             }
             $client = new Clients();
             $client->setFio($data['fio']);
             $client->setService(ServiceDAO::getInstance($this->getServiceLocator())->findOneById($data['service']));
             $client->setDiagnosis($data['diagnosis']);
             $client->setContacts($data['contacts']);
             $client->setDOS($data['dos']);
             $client->setStatus($data['status']);
             $client->setComments($data['comments']);
             $client->setCountry(CountryDAO::getInstance($this->getServiceLocator())->findOneById($data['country']));
             $client->setNextContactDate($data['nextContactDate']);
             $client->setNextContactComment($data['nextContactComment']);
             $client->setAttachments(serialize($attachmentNames));
             $client->setClinic(ClinicDAO::getInstance($this->getServiceLocator())->findOneById($data['clinic']));
             $client->setDoctor(DoctorDAO::getInstance($this->getServiceLocator())->findOneById($data['doctor']));
             $client->setConclusion(serialize(array_unique($conclusionNames)));
             $client->setPayment($data['payment']);
             $client->setInformed((int) $data['informed']);
             $client->setDateAdded($now);
             $client->setManager($applicationManager->getCurrentUser());
             ClientsDAO::getInstance($this->getServiceLocator())->save($client);
             if (!empty($data['nextContactDate'])) {
                 $calendarDAO = CalendarDAO::getInstance($this->getServiceLocator());
                 $event = new Calendar();
                 $event->setTitle($data['fio']);
                 $event->setDescription($client->getNextContactComment());
                 $event->setDate($client->getNextContactDate());
                 $event->setClient($client);
                 $calendarDAO->save($event);
             }
             return $this->redirect()->toRoute('clients');
         }
     }
     return array('form' => $form);
 }