public function loginAction()
{
if ($this->getServiceLocator()->get('Auth')->hasIdentity()) {
$redirect = $this->getRouteMatch()->getParam('redirect');
if (!empty($redirect)) {
return $this->redirect()->toUrl(base64_decode($redirect));
}
return $this->redirect()->toRoute('admin');
}
$this->layout()->setTemplate('layouts/one-page.phtml');
$loginForm = new UserLogin();
$post = $this->getRequest()->getPost();
if ($this->getRequest()->isPost() and $loginForm->setData($post->toArray()) and $loginForm->isValid()) {
$userModel = new User\Model();
$redirect = $loginForm->getValue('redirect');
if ($userModel->authenticate($post->get('login'), $post->get('password'))) {
if (!empty($redirect)) {
return $this->redirect()->toUrl(base64_decode($redirect));
}
return $this->redirect()->toRoute('admin');
}
$this->flashMessenger()->addErrorMessage('Can not connect');
return $this->redirect()->toRoute('config/user/login', array('redirect' => $redirect));
}
$loginForm->get('redirect')->setValue($this->getRouteMatch()->getParam('redirect'));
return array('form' => $loginForm);
}