public function processAction() { if (!$this->request->isPost()) { return $this->redirect()->toRoute(NULL, array('controller' => 'login', 'action' => 'index')); } $post = $this->request->getPost(); $form = new LoginForm(); $inputFilter = new LoginFilter(); $form->setInputFilter($inputFilter); $form->setData($post); if (!$form->isValid()) { $model = new ViewModel(array('error' => true, 'form' => $form)); $model->setTemplate('users/login/index'); return $model; } else { $this->getAuthService()->getAdapter()->setIdentity($this->request->getPost('email'))->setCredential($this->request->getPost('password')); $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { $this->getAuthService()->getStorage()->write($this->request->getPost('email')); return $this->redirect()->toRoute(NULL, array('controller' => 'login', 'action' => 'confirm')); } else { $model = new ViewModel(array('error' => true, 'form' => $form)); $model->setTemplate('users/login/index'); return $model; } } }
public function loginAction() { $this->layout('layout/login'); $request = $this->getRequest(); $loginForm = new LoginForm('loginForm'); $loginForm->setInputFilter(new LoginFilter()); $errors = array(); if ($this->getServiceLocator()->get('AuthService')->hasIdentity()) { return $this->redirect()->toRoute('home'); } if ($request->isPost()) { $data = $request->getPost(); $loginForm->setData($data); if ($loginForm->isValid()) { $data = $loginForm->getData(); $this->getAuthService()->getAdapter()->setIdentity($data['userid'])->setCredential(md5($data['password'])); $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { $userRow = $this->getAuthService()->getAdapter()->getResultRowObject(null, 'password'); if ($userRow && $userRow->status) { $branchsTable = $this->getTable($this->branchsTable, 'Application\\Model\\BranchsTable'); if ($branch = $branchsTable->findWithCompany($userRow->branch_id)) { $userRow->branch = $branch; $this->getAuthService()->getStorage()->write($userRow); return $this->redirect()->toRoute('home'); } else { $session = new Container('User'); $session->getManager()->destroy(); $this->getAuthService()->clearIdentity(); $errors[] = 'Sorry! your account is disable.'; } } else { $session = new Container('User'); $session->getManager()->destroy(); $this->getAuthService()->clearIdentity(); $errors[] = 'Sorry! your account is disable.'; } } else { $errors[] = 'Invalid login details.'; } } } return new ViewModel(array('loginForm' => $loginForm, 'errors' => $errors)); }
public function loginAction() { if ($this->request->isGet()) { $form = new LoginForm(); $view = new ViewModel(['form' => $form]); $view->setTemplate('users/index/login'); return $view; } else { if ($this->request->isPost()) { $post = $this->request->getPost(); $form = new LoginForm(); $inputFilter = new LoginFilter(); $form->setInputFilter($inputFilter); $form->setData($post); if (!$form->isValid()) { $view = new ViewModel(['error' => true, 'form' => $form]); $view->setTemplate('users/index/login'); return $view; } return $this->redirect()->toRoute(null, ['controller' => 'index', 'action' => 'login']); } } return $this->redirect()->toRoute(null, ['controller' => 'index', 'action' => 'login']); }
/** * Login Form Action * * @author Kaushal Kishore <*****@*****.**> * @package Users * @access Public * @return Object ViewModel */ public function indexAction() { $config = $this->getServiceLocator()->get('Config'); $userPassword = $this->getServiceLocator()->get('Users\\Service\\UserEncryption'); $session = new Container('User'); $viewModel = new ViewModel(); $loginForm = new LoginForm('loginForm'); $request = $this->getRequest(); $message = array(); // //Redirect to the Home Page if user already login//// if ($session->offsetExists('userId')) { return $this->redirect()->toRoute($config['afterLoginURL']); } try { if ($request->isPost()) { $clientInfo = ""; $loginValidation = new LoginValidation('loginValidation'); $loginForm->setInputFilter($loginValidation->getInputFilter()); $loginForm->setData($request->getPost()); if ($loginForm->isValid()) { $data = $loginForm->getData(); $userTable = $this->getServiceLocator()->get('Users\\Model\\UsersTable'); // ///////Check the Login Wrong Attempts ////////// $attempts = $userTable->getLoginAttempts($data['userName']); if ($attempts > 4) { $message['error'] = LoginMessages::LOGIN_LOCKED; $this->flashMessenger()->addMessage($message); return $this->redirect()->toRoute('users'); } $userDetails = $userTable->getUserDetailByUsername($data['userName']); // ///Validate the User Login Details//// $encyptPass = $userPassword->create($data['password']); $this->getAuthService()->getAdapter()->setIdentity($data['userName'])->setCredential($encyptPass); $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { $userDetails = $userTable->getUserDetailByUsername($data['userName']); if ($userDetails['status'] === 'Active') { $userTable->resetLoginAttempts($data['userName']); // ///Remember Me Functionality /////// if ($data['rememberMe'] == 1) { $this->getSessionStorage()->setRememberMe(1); $this->getAuthService()->setStorage($this->getSessionStorage()); } // ///Change Password From Functionality /////// if (isset($data['changePassword']) && $data['changePassword'] == 1) { return $this->redirect()->toUrl('users/change-password'); } $this->getAuthService()->getStorage()->write($data['userName']); $session->offsetSet('userId', $userDetails['id']); $session->offsetSet('userEmail', $data['userName']); } else { // //// Destroy the Session and redirect to Login $message['error'] = LoginMessages::ACCOUNT_NOT_ACTIVE; $this->flashMessenger()->addMessage($message); return $this->redirect()->toRoute('users'); } return $this->redirect()->toRoute($config['afterLoginURL']); } else { $message['error'] = LoginMessages::INVALID_USER_PASSWORD; $this->flashMessenger()->addMessage($message); return $this->redirect()->toRoute('users'); } } else { $errorList = $loginForm->getMessages(); $message['error'] = ''; if (isset($errorList['loginCsrf']['notSame'])) { $message['error'] = LoginMessages::CSRF_ERROR; } if (empty($message['error'])) { $message['error'] = "Invalid Email and Password"; } $this->flashMessenger()->addMessage($message); // return $this->redirect()->toRoute('users'); } } } catch (\Exception $excp) { print "<pre>"; print_r($excp->getMessage()); die; $excp->getMessage(); } $viewModel->setVariables(array('loginForm' => $loginForm)); return $viewModel; }