Beispiel #1
0
 /**
  * validate data and register user in DB
  *
  * @return ViewModel
  */
 public function processAction()
 {
     if ($this->request->isPost()) {
         $form = new RegisterForm();
         $data = $this->params()->fromPost();
         $viewModel = new ViewModel();
         $viewModel->setTemplate('user/register/index');
         $viewModel->setVariable("registerForm", $form);
         $form->setData($data);
         if ($form->isValid()) {
             if ($data["password"] == $data["confirm_password"]) {
                 $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
                 $user = $em->getRepository('Application\\Entity\\User')->findByEmail($data['email']);
                 if ($user) {
                     $viewModel->setVariable('accountExistError', true);
                     return $viewModel;
                 }
                 $user = new User();
                 $user->setFirstname($data['firstname']);
                 $user->setLastname($data['lastname']);
                 $user->setEmail($data['email']);
                 $user->setPhone($data['phone']);
                 $user->setPassword($data['password']);
                 $user->setGender($data['gender']);
                 $user->setBlocked(0);
                 $user->setEmailVerified(0);
                 $user->setPhoneVerified(0);
                 $user->setBanned(0);
                 $user->setRole('u');
                 $user->setExperience(0);
                 $user->setBirthYear($data['birthyear']);
                 $user->setRegistredDate(time());
                 $em->persist($user);
                 $em->flush();
                 $params = ["email" => $user->getEmail()];
                 //$eventManager = $this->getEventManager()->trigger('sendMail', null, );
                 //TODO continue and send mail by Listener class
                 $this->redirect()->toRoute('user', ['controller' => 'register', 'action' => 'success']);
             } else {
                 $viewModel->setVariable('passwordError', true);
                 return $viewModel;
             }
         } else {
             $viewModel->setVariable('formError', true);
             return $viewModel;
         }
     } else {
         $this->redirect()->toRoute('user', ['controller' => "register", "action" => "index"]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setFirstname($firstname)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setFirstname', array($firstname));
     return parent::setFirstname($firstname);
 }