/** * Login action method * * @return void */ public function login() { $this->prepareView('login.phtml'); $this->view->title = 'Please Login'; $this->view->form = new Form\Login($this->application->config()['forms']['App\\Form\\Login']); if ($this->request->isPost()) { $auth = new Auth\Auth(new Auth\Adapter\Table('App\\Table\\Users', Auth\Auth::ENCRYPT_BCRYPT)); $this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($this->request->getPost(), $auth); $user = new Model\User(); $session = new Model\Session(); if ($this->view->form->isValid() && $session->validate($auth->adapter()->getUser(), $this->application->config())) { $user->login($auth->adapter()->getUser(), $this->sess, $this->application->config()); $this->redirect('/'); } else { if (null !== $auth->adapter()->getUser() && null !== $auth->adapter()->getUser()->id) { $user->failed($auth->adapter()->getUser()); if ($this->view->form->isValid()) { $this->sess->setRequestValue('failed', true); $this->redirect('/login'); } } } } $this->send(); }