public function indexAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $user = new User();
     //1)  A lot of work to manualy change the form add fields etc. Better use a form class
     //-		$form = $this->getRegistrationForm($entityManager, $user);
     // 2) Better use a form class
     $form = new RegistrationForm();
     $form->get('submit')->setValue('Register');
     $form->setHydrator(new DoctrineHydrator($entityManager, 'Aut\\Entity\\User'));
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->prepareData($user);
             $entityManager->persist($user);
             $entityManager->flush();
             $mail = new MailController();
             $mail->initMail('accountCreated', $user->getUsrEmail(), $user->getUsrName());
             return $this->redirect()->toRoute('auth/default', array('controller' => 'registration', 'action' => 'registration-success'));
         }
     }
     return new ViewModel(array('form' => $form));
 }
Esempio n. 2
0
 public function registrationAction()
 {
     $form = new RegistrationForm();
     $auth = new AuthenticationService();
     $status = $message = '';
     if ($auth->hasIdentity()) {
         // Identity exists
         return $this->redirect()->toRoute('store');
     }
     /**
      * @var $request Request
      */
     $request = $this->getRequest();
     if ($request->isPost()) {
         $filters = new MyRegistrationFilter();
         $form->setInputFilter($filters->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //add user
             $userData = $form->getData();
             $user = new User();
             $user->exchangeArray($form->getData());
             $user->addUser();
             //Authentication
             $authAdapter = new MyAuthAdapter($userData['name'], md5($userData['pass']));
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 $status = 'success';
                 $message = 'Реєстрація пройшла успішно';
                 if ($message) {
                     $this->flashMessenger()->setNamespace($status)->addMessage($message);
                 }
                 return $this->redirect()->toRoute('store');
             } else {
                 $status = 'error';
                 $message = 'Виникла непередбачувана помилка';
             }
         } else {
             $status = 'error';
             $message = 'Помилка параметрів';
         }
     }
     //make message
     if ($message) {
         $this->flashMessenger()->setNamespace($status)->addMessage($message);
     }
     return array('form' => $form);
 }
Esempio n. 3
0
 public function indexAction()
 {
     $form = new RegistrationForm();
     $form->get('submit')->setValue('Register');
     $request = $this->getRequest();
     // съдържа данните преди валидация
     if ($request->isPost()) {
         $form->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             //съдържа данните след валидация
             $data = $this->prepareData($data);
             $auth = new Auth();
             $auth->exchangeArray($data);
             //echo '<pre>';
             //print_r($auth);
             //echo '</pre>';
             /*
                            //Manualy, without ServiceManager
                            $dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new Auth());
                            $tableGateway = new TableGateway('users', $dbAdapter, null, $resultSetPrototype);
                            $usersTable = new UsersTable($tableGateway);
                            $usersTable->saveUser($auth);
                            $userIvan = $usersTable->getUser(5);
                            
                            //without $userTable
                            $rowset = $tableGateway->select(array('usr_id' => 5));
                            $user3 = $rowset->current();
                            echo '<pre>';
                            print_r($user3);
                            echo '</pre>';
             */
             //using the ServiceManager
             $this->getUsersTable()->saveUser($auth);
             $this->sendConfirmationEmail($auth);
             $this->flashMessenger()->addMessage($auth->usr_email);
             return $this->redirect()->toRoute('auth/default', array('controller' => 'registration', 'action' => 'registration-success'));
         }
     }
     return new viewModel(array('form' => $form));
 }
Esempio n. 4
0
 public function indexAction()
 {
     // A test instantiation to make sure it works. Not used in the application. You can remove the next line
     // $myValidator = new ConfirmPassword();
     $form = new RegistrationForm();
     $form->get('submit')->setValue('Register');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $data = $this->prepareData($data);
             $auth = new Auth();
             $auth->exchangeArray($data);
             /*				
             				// this is replaced by 
             				// 1) Manualy composing (wiring) the objects
             				$dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
             				$resultSetPrototype = new \Zend\Db\ResultSet\ResultSet();
             				$resultSetPrototype->setArrayObjectPrototype(new \Auth\Model\Auth());
             				$tableGateway = new \Zend\Db\TableGateway\TableGateway('users', $dbAdapter, null, $resultSetPrototype);
             				$usersTable = new \Auth\Model\UsersTable($tableGateway);
             				// $usersTable->saveUser($auth);
             				// $user7 = $usersTable->getUser(7);
             				
             				$rowset = $tableGateway->select(array('usr_id' => 7));
             				$user7 = $rowset->current();
             				
             				echo '<pre>';
             				var_dump($user7);
             				echo '</pre>';
             */
             // OR
             // 2) Using the service Locator
             $this->getUsersTable()->saveUser($auth);
             $this->sendConfirmationEmail($auth);
             $this->flashMessenger()->addMessage($auth->usr_email);
             return $this->redirect()->toRoute('auth/default', array('controller' => 'registration', 'action' => 'registration-success'));
         }
     }
     return new ViewModel(array('form' => $form));
 }