예제 #1
0
 public function registraceAction()
 {
     if (!isset($this->logged->nick)) {
         $form = new RegisterForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $register = new User();
             $register->setInputs(['nick', 'heslo', 'email']);
             $form->setInputFilter($register->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 if ($form->getData()['heslo'] == $form->getData()['heslo_repeat']) {
                     $table = $this->getUserTable();
                     $data = array('nick' => $form->getData()['nick'], 'heslo' => $form->getData()['heslo'], 'email' => $form->getData()['email']);
                     $register->exchangeArray($data);
                     $bool = $table->register($register);
                     if ($bool === true) {
                         $this->logged->nick = $register->nick;
                         $this->logged->admin = 0;
                         // redirect
                     } else {
                         if ($bool == 'nick') {
                             $error = $this->msg->get('login.error.nickUsed', ['nick' => $data['nick']]);
                         } else {
                             if ($bool == 'email') {
                                 $error = $this->msg->get('login.error.emailUsed', ['email' => $data['email']]);
                             } else {
                                 $error = $this->msg->get('other.error.unknownError');
                             }
                         }
                     }
                 } else {
                     $error = $this->msg->get('login.error.passwordsNotMatching');
                 }
             } else {
                 $error = $this->msg->get('form.error.invalidData');
             }
         }
         return array('form' => $form, 'error' => isset($error) ? $error : null, 'menu' => new Menu($this->url()->fromRoute("application"), array("login", "registrace", "obnovit" => "zapomenuté heslo"), "registrace"));
     } else {
         return $this->redirect()->toRoute('application/default', array('controller' => 'profil'));
     }
 }