Пример #1
0
 /**
  * the registration action- Either returns the registration page or adds an account to the db and sends out an email.
  *
  * @return array|\Zend\Http\Response
  */
 public function registerAction()
 {
     $form = new RegisterForm();
     $form->get('submit')->setValue('Register');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $account = new Account();
         $form->setInputFilter($account->getRegisterInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $account->exchangeArray($form->getData());
             if (!$this->getAccountTable()->getAccountBy(['name' => $account->getName()])) {
                 if (!$this->getAccountTable()->getAccountBy(['email' => $account->getEmail()])) {
                     $account->setUserHash(hash('sha256', $account->getName()));
                     $this->getAccountTable()->saveAccount($account);
                     $this->sendConfirmationMail($account);
                 } else {
                     return ['form' => $form, 'errors' => $errors = ['email' => 'email_taken']];
                 }
             } else {
                 return ['form' => $form, 'errors' => $errors = ['name' => 'name_taken']];
             }
             return $this->redirect()->toRoute('auth', ['action' => 'registersuccess']);
         } else {
             $errors = $form->getMessages();
             return ['form' => $form, 'errors' => $errors];
         }
     }
     return ['form' => $form];
 }