public function indexAction() { $layout = $this->layout(); $layout->setTemplate('layout/login'); $form = new AdminForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { //echo '<pre>'; print_r($request->getPost()); //exit; $admin = new Admin(); $form->setInputFilter($admin->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $username = $request->getPost('email'); $password = $request->getPost('password'); $this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password); $result = $this->getAuthService()->authenticate(); foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } if ($result->isValid()) { //$redirect = 'success'; //check if it has rememberMe : if ($request->getPost('rememberme') == 1) { $this->getSessionStorage()->setRememberMe(1); //set storage again $this->getAuthService()->setStorage($this->getSessionStorage()); } $this->getAuthService()->getStorage()->write($request->getPost('email')); return $this->redirect()->toRoute('admin', array('action' => 'dashboard')); } else { return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action' => 'index', 'id' => 0)); } /*if($email == '*****@*****.**' && $password == 'welcome1') { $sessionAdmin = new Container('admin'); $sessionAdmin->email = $email ; $sessionAdmin->isvalid = "yes"; return $this->redirect()->toRoute('admin', array('action'=>'dashboard')); } else { return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action'=>'index','id'=>0)); } */ } } return array('form' => $form, 'messages' => $this->flashmessenger()->getMessages()); //return new ViewModel(); /* return new ViewModel(array( 'admins' => $this->getAdminTable()->fetchAll(), )); */ }
public function indexAction() { // If already login then redirect to dashboard. if ($this->getServiceLocator()->get('AuthService')->hasIdentity()) { return $this->redirect()->toRoute('admin', array('action' => 'dashboard')); } $layout = $this->layout(); $layout->setTemplate('layout/login'); $form = new AdminForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $admin = new Admin(); $form->setInputFilter($admin->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $username = $request->getPost('email'); $password = $request->getPost('password'); $this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password); $result = $this->getAuthService()->authenticate(); foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } if ($result->isValid()) { $sessionAdmin = new Container('admin'); $sessionAdmin->email = $username; $sessionAdmin->isvalid = "yes"; return $this->redirect()->toRoute('admin', array('action' => 'dashboard')); } else { return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action' => 'index', 'id' => 0)); } } } return array('form' => $form, 'messages' => $this->flashmessenger()->getMessages()); }
public function loginAction() { // $user = $this->identity(); $user = new User($this->getServiceLocator()); $form = new AdminForm(); $form->get('submit')->setValue('Login'); $messages = null; $request = $this->getRequest(); if ($request->isPost()) { $userdetail = $user->getUserId($request); if ($userdetail) { $messages = "Successful login"; $container = new Container('adminloginuser'); $container->userdetail = $userdetail; $container->userid = $userdetail['id']; return $this->redirect()->toRoute('admin/default', array('controller' => 'index', 'action' => 'index')); } else { $messages = "Error login"; return new ViewModel(array('form' => $form, 'messages' => $messages)); } } else { return new ViewModel(array('form' => $form)); } }