public function addAction()
 {
     $error = '';
     $token = $this->params()->fromRoute('token');
     $form = new RegisterForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $exUser = $this->getEntityManager()->getRepository('Profile\\Entity\\User')->findByusername($request->getPost('username'));
         if (empty($exUser)) {
             $user = new User();
             $filter = new RegisterFilter();
             $form->bind($user);
             $form->setInputFilter($filter->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $check = $this->getProfileService()->addUser($user, $form, $request);
                 if ($check === true) {
                     return $this->redirect()->toRoute('home');
                 } else {
                     return array('form' => $form);
                 }
             }
         } else {
             $this->flashMessenger()->addErrorMessage('Der Username ist bereits vergeben. Bitte wähle einen anderen.');
         }
     }
     return array('form' => $form, 'error' => $this->flashMessenger()->getErrorMessages());
 }
 /**
  * registerAction
  * @return \Zend\Http\Response|multitype:\Profile\Form\RegisterForm |multitype:\Profile\Form\RegisterForm multitype:
  */
 public function registerAction()
 {
     $error = '';
     $token = $this->params()->fromRoute('token');
     if (!empty($token)) {
         $check = $this->getProfileService()->confirmUser($token);
         if ($check === true) {
             $this->flashMessenger()->addMessage('Freischaltung erfolgreich. Du kannst dich nun einloggen.');
             return $this->redirect()->toRoute('login');
         }
         $this->flashMessenger()->addErrorMessage('Der angegebene Token ist ungültig oder der Account wurde bereits' . ' aktiviert. Bitte registriere dich oder logge dich ein.');
     }
     $form = new RegisterForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $exUser = $this->getEntityManager()->getRepository('Profile\\Entity\\User')->findByusername($request->getPost('username'));
         if (empty($exUser)) {
             $user = new User();
             $filter = new RegisterFilter();
             $form->bind($user);
             $form->setInputFilter($filter->getInputFilter());
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $check = $this->getProfileService()->addUser($user, $form, $request);
                 if ($check === true) {
                     return $this->redirect()->toRoute('home');
                 } else {
                     return array('form' => $form);
                 }
             }
         } else {
             $this->flashMessenger()->addErrorMessage('Der Username ist bereits vergeben. Bitte wähle einen anderen.');
         }
     }
     return array('form' => $form, 'error' => $this->flashMessenger()->getErrorMessages());
 }