/** * signin */ public function signinAction() { /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $redirect = trim($request->getQuery('redirect')); if ($this->user()->hasIdentity()) { if (!$redirect) { $authorize = $this->getServiceLocator()->get('\\Authorize\\Service\\Authorize'); if (!$authorize->isAllowed('company:announcement', 'index')) { return $this->redirect()->toRoute('home'); } else { return $this->redirect()->toRoute('company'); } } return $this->redirect()->toUrl($redirect); } $sl = $this->getServiceLocator(); $form = new \User\Form\Signin($this->getServiceLocator()); //$form = new \User\Form\Signin(); $failNumber = isset($_SESSION['failNumber']) ? $_SESSION['failNumber'] : 0; if ($failNumber < 2) { $form->removeCaptcha(); } if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $_SESSION['failNumber'] = 0; $userService = $this->getServiceLocator()->get('User\\Service\\User'); /* if($userService->getIdentity() && $userService->getUser()){ if(!$userService->getUser()->getEmployeeCode()){ return $this->redirect()->toUrl(Uri::build('/user/user/updatecode', ['redirect'=>$redirect])); } } */ if (!$redirect) { $authorize = $this->getServiceLocator()->get('\\Authorize\\Service\\Authorize'); if (!$authorize->isAllowed('company:announcement', 'index')) { return $this->redirect()->toRoute('home'); } else { return $this->redirect()->toRoute('company'); } } return $this->redirect()->toUrl($redirect); // $username = $form->getInputFilter()->getValue('username'); // $password = $form->getInputFilter()->getValue('password'); // /* @var $serviceUser \User\Service\User */ // $serviceUser = $this->getServiceLocator()->get('User\Service\User'); // // @todo show captcha after signing 3 times failed // if(!$serviceUser->authenticate($username, $password)) { // $form->showInvalidMessage(); // } else { // /* @var $user \User\Model\User */ // $user = $serviceUser->getUser(); // if(!$user) { // return; // } // if(!$user->getLocked() && $user->getActive()) { // if (!$redirect) { // return $this->redirect()->toRoute('home'); // } else { // return $this->redirect()->toUrl($redirect); // } // } // if($user->getLocked()) { // $form->showInvalidMessage(\User\Form\Signin::ERROR_LOCKED); // } // if(!$user->getActive()) { // $form->showInvalidMessage(\User\Form\Signin::ERROR_INACTIVE); // } // } } else { $_SESSION['failNumber'] = ++$failNumber; if ($failNumber >= 10) { $username = $form->getInputFilter()->getValue('username'); $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper'); if (!!($user = $userMapper->get(null, $username))) { $userMapper->updateColumns(['locked' => 1], $user); $form->get('username')->setMessages([$form::ERROR_LOCKED]); } } } } $viewModel = new ViewModel(array('form' => $form, 'redirect' => $redirect)); if ($this->params()->fromQuery('layout') == 'false') { $viewModel->setTerminal(true); } return $viewModel; }
/** * signin */ public function signinAction() { /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $redirect = $request->getQuery('redirect'); $sl = $this->getServiceLocator(); $form = new \User\Form\Signin($this->getServiceLocator()); $failNumber = isset($_SESSION['failNumber']) ? $_SESSION['failNumber'] : 0; if ($failNumber < 2) { $form->removeCaptcha(); } if ($this->user()->getIdentity()) { $viewModel = new ViewModel(); return $viewModel->setTemplate('error/403'); } if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $_SESSION['failNumber'] = 0; $userService = $this->getServiceLocator()->get('User\\Service\\User'); /* if($userService->getIdentity() && $userService->getUser()){ if(!$userService->getUser()->getEmployeeCode()){ return $this->redirect()->toUrl(Uri::build('/user/user/updatecode', ['redirect'=>$redirect])); } } */ // if (!$redirect) { // $authorize = $this->getServiceLocator()->get('\Authorize\Service\Authorize'); // if(!$authorize->isAllowed('company:announcement', 'index')){ // return $this->redirect()->toRoute('home'); // }else{ // return $this->redirect()->toRoute('company'); // } // } if ($userService->getUser()->getRole() == User::ROLE_CALLCENTER) { return $this->redirect()->toUrl('/home/callcenter'); } if ($userService->isAdmin()) { return $this->redirect()->toUrl('/admin'); } // return $this->redirect()->toUrl($redirect); $username = $form->getInputFilter()->getValue('mail'); $password = $form->getInputFilter()->getValue('password'); // /* @var $serviceUser \User\Service\User */ // $serviceUser = $this->getServiceLocator()->get('User\Service\User'); // // @todo show captcha after signing 3 times failed if (!$userService->authenticate($username, $password)) { // $form->showInvalidMessage(); $form->get('mail')->setMessages(['tai khaonr']); } else { /* @var $user \User\Model\User */ $user = $userService->getUser(); if (!$user) { return; } if ($user->getLocked() == User::UNLOCKED && $user->getActive()) { if (!$redirect) { if ($user->getRole() == User::ROLE_CALLCENTER) { return $this->redirect()->toUrl('/home/callcenter'); } return $this->redirect()->toUrl('/'); } else { return $this->redirect()->toUrl($redirect); } } if ($user->getLocked() == User::LOCKED) { $form->get('mail')->setMessages([\User\Form\Signin::ERROR_LOCKED]); } if (!$user->getActive()) { $form->get('mail')->setMessages([\User\Form\Signin::ERROR_INACTIVE]); } } } else { $_SESSION['failNumber'] = ++$failNumber; if ($failNumber >= 10) { $email = $form->getInputFilter()->getValue('mail'); $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper'); if (!!($user = $userMapper->get(null, null, $email))) { $userMapper->updateColumns(['locked' => 1], $user); $form->get('mail')->setMessages([$form::ERROR_LOCKED]); } } if ($failNumber < 10 && $failNumber > 3) { $form->get('mail')->setMessages(['Bạn còn ' . (10 - $failNumber) . ' lần đăng nhập sai!']); } } } $viewModel = new ViewModel(array('form' => $form, 'redirect' => $redirect)); if ($this->params()->fromQuery('layout') == 'false') { $viewModel->setTerminal(true); } return $viewModel; }