public function loginAction() { $request = $this->getRequest(); $view = new ViewModel(); $loginForm = new LoginForm('loginForm'); $loginForm->setInputFilter(new LoginFilter()); if ($request->isPost()) { $data = $request->getPost(); $loginForm->setData($data); if ($loginForm->isValid()) { $data = $loginForm->getData(); $userPassword = new UserPassword(); $encyptPass = $userPassword->create($data['password']); $this->getAuthService()->getAdapter()->setIdentity($data['email'])->setCredential($encyptPass); $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { $session = new Container('User'); $session->offsetSet('email', $data['email']); $this->flashMessenger()->addMessage(array('success' => 'Login Success.')); // Redirect to page after successful login } else { $this->flashMessenger()->addMessage(array('error' => 'invalid credentials.')); // Redirect to page after login failure } return $this->redirect()->tourl('/article_to_read/public/device'); // Logic for login authentication } else { $errors = $loginForm->getMessages(); //prx($errors); } } $view->setVariable('loginForm', $loginForm); return $view; }
public function authenticateAction() { $oLoginForm = new LoginForm(); $request = $this->getRequest(); if ($request->isPost()) { $oLoginForm->setData($request->getPost()); $oLoginFilter = new LoginFilter(); $oLoginForm->setInputFilter($oLoginFilter->getInputFilter()); if ($oLoginForm->isValid()) { $this->getAuthService()->getAdapter()->setIdentity($request->getPost('login'))->setCredential(md5($request->getPost('password'))); $result = $this->getAuthService()->authenticate(); foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } if ($result->isValid()) { $aUser = $this->getAuthService()->getAdapter()->getResultRowObject(); $this->getAuthService()->getStorage()->write($aUser); return $this->redirect()->toRoute('success'); } } else { $this->flashmessenger()->addMessage($oLoginForm->getMessages()); } } return $this->redirect()->toRoute('auth'); }