コード例 #1
0
 public function registerAction()
 {
     $registerForm = new Register();
     $registerForm->setInputFilter(new \Frontend\Login\Form\Filter\Register($this->getEntityManager()));
     $loginForm = new Login();
     $loginForm->init();
     if ($this->request->isPost()) {
         $registerForm->setData($this->getRequest()->getPost());
         if ($registerForm->isValid()) {
             $data = $registerForm->getData();
             $benutzer = new Benutzer();
             $benutzer->setUsername($data['username']);
             $benutzer->setPassword($data['password']);
             $benutzer->setEmail($data['email']);
             $benutzer->setDisabled(false);
             $benutzer->setRegisterDate(date('c'));
             $gruppe = $this->getEntityManager()->getReference('Auth\\Entity\\Role', 1);
             $benutzer->setGruppe($gruppe);
             $this->getEntityManager()->persist($benutzer);
             $this->getEntityManager()->flush();
             /** @var GATracking $analytics */
             $analytics = $this->getServiceLocator()->get(GATracking::class);
             /** @var Event $eventTracker */
             $eventTracker = $analytics->createTracking('Event');
             $eventTracker->setEventCategory('User');
             $eventTracker->setEventAction('Register');
             $eventTracker->setEventLabel($benutzer->getUsername());
             $eventTracker->setEventValue($benutzer->getId());
             $analytics->sendTracking($eventTracker);
             // login
             /** @var Acl $authService */
             $authService = $this->getServiceLocator()->get('AuthService');
             $authService->instantLogin($benutzer);
             return $this->redirect()->toRoute('frontend/user/home');
         } else {
             $registerForm->populateValues($this->getRequest()->getPost());
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('loginForm', $loginForm);
     $viewModel->setVariable('registerForm', $registerForm);
     $viewModel->setTemplate('/login/login.phtml');
     return $viewModel;
 }