示例#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(new \DateTime());
             $benutzer->addRole($this->getEntityManager()->getReference(Role::class, 2));
             $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 AuthenticationService $authService */
             $authService = $this->getServiceLocator()->get(AuthenticationService::class);
             $authService->forceLogin($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;
 }