コード例 #1
0
 /**
  * Administrationsbereich Login
  *
  * @return ViewModel
  */
 public function loginAction()
 {
     // wenn access vorhanden direkt weiter
     if ($this->hasAccess('frontend/dashboard/access')) {
         return $this->redirect()->toRoute('frontend/user/home');
     }
     // form
     $registerForm = new Register();
     $loginForm = new Login();
     $loginForm->init();
     // fallback uri
     $fallbackUrl = $this->Params()->fromQuery('fallback_url', false);
     if ($fallbackUrl) {
         // check if fallback have no domain
         $urlParse = parse_url($fallbackUrl);
         if (!$urlParse || !isset($urlParse['path'])) {
             // no valid fallback
             $fallbackUrl = false;
         } else {
             $fallbackUrl = $urlParse['path'];
         }
     }
     if ($this->request->isPost()) {
         $username = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $authService = $this->getServiceLocator()->get('AuthService');
         $loggedIn = $authService->login($username, $password);
         if ($loggedIn == Acl::LOGIN_WRONG) {
             $this->Message()->addErrorMessage('FRONTEND_LOGIN_AUTH_WRONG');
         } elseif ($loggedIn == Acl::LOGIN_DISABLED) {
             $this->Message()->addInfoMessage('FRONTEND_LOGIN_AUTH_BANNED');
         } elseif ($loggedIn == Acl::LOGIN_SUCCESS) {
             // last login
             /** @var Benutzer $benutzer */
             $benutzer = $this->identity();
             $benutzer->setLastLogin(date('c'));
             $this->getEntityManager()->merge($benutzer);
             $this->getEntityManager()->flush();
             if ($fallbackUrl) {
                 // redirect to fallback url
                 return $this->redirect()->toUrl($fallbackUrl);
             } else {
                 // redirect to user home
                 return $this->redirect()->toRoute('frontend/user/home');
             }
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('loginForm', $loginForm);
     $viewModel->setVariable('loginFallbackUrl', $fallbackUrl);
     $viewModel->setVariable('registerForm', $registerForm);
     $viewModel->setTemplate('/login/login.phtml');
     return $viewModel;
 }
コード例 #2
0
 /**
  * Administrationsbereich Login
  *
  * @return ViewModel
  */
 public function loginAction()
 {
     if ($this->identity()) {
         return $this->redirect()->toRoute('frontend/user/home');
     }
     // form
     $registerForm = new Register();
     $loginForm = new Login();
     $loginForm->init();
     // fallback uri
     $fallbackUrl = $this->Params()->fromQuery('fallback_url', false);
     if ($fallbackUrl) {
         // check if fallback have no domain
         $urlParse = parse_url($fallbackUrl);
         if (!$urlParse || !isset($urlParse['path'])) {
             // no valid fallback
             $fallbackUrl = false;
         } else {
             $fallbackUrl = $urlParse['path'];
         }
     }
     if ($this->request->isPost()) {
         $username = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $authService = $this->getServiceLocator()->get(AuthenticationService::class);
         $authService->getAdapter()->setCredentials($username, $password);
         /** @var Result $result */
         $result = $authService->authenticate();
         if ($result->isValid()) {
             if ($fallbackUrl) {
                 // redirect to fallback url
                 return $this->redirect()->toUrl($fallbackUrl);
             }
             // redirect to user home
             return $this->redirect()->toRoute('frontend/user/home');
         } else {
             $lastResultMessage = current($result->getMessages());
             $this->flashMessenger()->addErrorMessage($lastResultMessage);
             $loginForm->populateValues($this->getRequest()->getPost());
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('loginForm', $loginForm);
     $viewModel->setVariable('loginFallbackUrl', $fallbackUrl);
     $viewModel->setVariable('registerForm', $registerForm);
     $viewModel->setTemplate('/login/login.phtml');
     return $viewModel;
 }