Example #1
0
 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;
         }
     }
 }
Example #2
0
 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));
 }
Example #3
0
 public function getServiceConfig()
 {
     return array('abstract_factories' => array(), 'aliases' => array(), 'factories' => array('UsersTable' => function ($sm) {
         // echo __METHOD__." is reached; test echo in line ".__LINE__;
         $tableGateway = $sm->get('UsersTableGateway');
         $table = new UsersTable($tableGateway);
         return $table;
     }, 'UsersTableGateway' => function ($sm) {
         //echo __METHOD__." is reached; test echo in line ".__LINE__;
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new Users());
         return new TableGateway('users', $dbAdapter, null, $resultSetPrototype);
     }, 'LoginForm' => function ($sm) {
         $form = new LoginForm();
         $form->setInputFilter($sm->get('LoginFormFilter'));
         return $form;
     }, 'RegisterForm' => function ($sm) {
         $form = new RegisterForm();
         $form->setInputFilter($sm->get('RegisterFormFilter'));
         return $form;
     }, 'UserEditForm' => function ($sm) {
         $form = new UserEditForm();
         $form->setInputFilter($sm->get('UserEditFormFilter'));
         return $form;
     }, 'UserAddForm' => function ($sm) {
         $form = new UserAddForm();
         $form->setInputFilter($sm->get('UserAddFormFilter'));
         return $form;
     }, 'LoginFormFilter' => function ($sm) {
         return new LoginFormFilter();
     }, 'RegisterFormFilter' => function ($sm) {
         return new RegisterFormFilter();
     }, 'UserEditFormFilter' => function ($sm) {
         return new UserEditFormFilter();
     }, 'UserAddFormFilter' => function ($sm) {
         return new UserAddFormFilter();
     }), 'invokables' => array(), 'services' => array(), 'shared' => array());
 }
Example #4
0
 public function getServiceConfig()
 {
     return ['abstract_factories' => [], 'aliases' => [], 'factories' => ['UserTable' => function ($sm) {
         $tableGateway = $sm->get('UserTableGateway');
         $table = new UserTable($tableGateway);
         return $table;
     }, 'UserTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new User());
         return new TableGateway('user', $dbAdapter, null, $resultSetPrototype);
     }, 'LoginForm' => function ($sm) {
         $form = new LoginForm();
         $form->setInputFilter($sm->get('LoginFilter'));
         return $form;
     }, 'RegisterForm' => function ($sm) {
         $form = new RegisterForm();
         $form->setInputFilter($sm->get('RegisterFilter'));
         return $form;
     }, 'UserEditForm' => function ($sm) {
         $form = new UserEditForm();
         $form->setInputFilter($sm->get('UserEditFilter'));
         return $form;
     }, 'LoginFilter' => function ($sm) {
         return new LoginFilter();
     }, 'RegisterFilter' => function ($sm) {
         return new RegisterFilter();
     }, 'UserEditFilter' => function ($sm) {
         return new UserEditFilter();
     }, 'AuthService' => function ($sm) {
         $authService = new AuthenticationService();
         $authService->setAdapter($sm->get('TableAuthAdapter'));
         return $authService;
     }, 'TableAuthAdapter' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         return new DbTableAuthAdapter($dbAdapter, 'user', 'email', 'password', 'MD5(?)');
     }], 'invokables' => [], 'services' => [], 'shared' => []];
 }
 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;
 }