/** * Ensure that ResultRowObject returns an object has specific omissions */ public function testGetOmittedResultRow() { $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); $this->_adapter->authenticate(); $resultRow = $this->_adapter->getResultRowObject(null, 'password'); $this->assertEquals('O:8:"stdClass":3:{s:2:"id";s:1:"1";s:8:"username";s:11:"my_username";s:9:"real_name";s:12:"My Real Name";}', serialize($resultRow)); }
public function loginAction() { $entityManager = $this->getEntityManager(); $form = new LoginForm($entityManager); $error = null; $request = $this->getRequest(); if ($request->isPost()) { $formInputFilter = new LoginFilter($entityManager); $form->setInputFilter($formInputFilter->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $formData = $form->getData(); $authAdapter = new AuthAdapter($this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'users', 'login', 'password', "MD5(?)"); $authAdapter->setIdentity($formData["loginutilisateur"])->setCredential($formData["passwordutilisateur"]); $authResultat = $authAdapter->authenticate(); if ($authResultat->isValid()) { $userData = $authAdapter->getResultRowObject(); if ($userData->acces == '4') { $error = 'Votre compte a été supprimé'; } elseif ($userData->acces == '3') { $authService = new AuthenticationService(); $authService->getStorage()->write($userData); // TODO Redirections selon profil utilisateur switch ($userData->type) { default: // $this->redirect()->toUrl($this->getBaseUrl()); $this->redirect()->toRoute("home"); } } else { $error = 'Votre compte est désactivé'; } } else { $error = 'Identifiants incorrects'; } } else { $error = 'Identifiants incorrects'; } } return new ViewModel(array('form' => $form, 'alertmessages' => array('error' => $error))); }
/** * This action is called when a user is to be authenticated by their username and password * * @return \Zend\View\Model\ViewModel */ public function authenticateAction() { $Logform = new LoginForm(); //Gets the username $email = $this->request->getPost('email'); //Get the password and encrypt it using md5 $password = md5($this->request->getPost('password')); //Create a connection to the database $db = $this->getServiceLocator()->get('dbcon'); if ($this->request->isPost()) { //Perform a check to see if username and password are not empty if ($email != null and $password != null) { //Create an instance of the Auth Adapter $auth = new AuthAdapter($db); //Set the user name $auth->setIdentity($email); //Set the password $auth->setCredential($password); //Set the Table name $auth->setTableName('users'); //Set the user name colum $auth->setIdentityColumn('email'); //Set the password column $auth->setCredentialColumn('password'); //Authenticate the user $auth->authenticate(); //If authentication is valid if ($auth->authenticate()->isValid()) { //Convert the user credentials from an object into an array $array = get_object_vars($auth->getResultRowObject()); //Set the username and store it in session $this->session->offsetSet('email', $array['email']); $this->session->offsetSet('username', $array['username']); //Set the user id and store in session $this->session->offsetSet('id', $array['id']); //Set the user full name and store in session $this->session->offsetSet('fullname', $array['full_name']); $this->AuthenticationLogger("user logged in successfully at " . date('y-m-d H:i:s')); $this->ActivityLogs("user logged in successfully at " . date('Y-m-d H:i:s')); //Redirect the user to the admin page $this->getUrl('ekontact', 'Ekontact', 'dashboard'); } else { $msg = $this->flashMessenger()->addMessage(sprintf(" %s Invalid email or password %s", '<div class="error">', '</div>')); return $this->redirect()->toRoute('authentication', array('controller' => 'Authentication', 'action' => 'login')); } } else { $msg = $this->flashMessenger()->addMessage(sprintf(" %s Please make sure both email and password fields are not empty %s", '<div class="error">', '</div>')); $this->getUrl('authentication', 'Authentication', 'login'); } } $view = new ViewModel(array('form' => $Logform)); $this->layout('layout/login_layout'); return $view; }
/** * @see \Zend\Authentication\Adapter\DbTable\AbstractAdapter::getResultRowObject() */ public function getResultRowObject($returnColumns = null, $omitColumns = null) { return parent::getResultRowObject(null, ['password']); }