/**
  *
  * @return Ambigous <\Zend\Http\Response, \Zend\Stdlib\ResponseInterface>
  */
 public function processAction()
 {
     $username = $this->params()->fromPost('username');
     $password = $this->params()->fromPost('passwd');
     $adapterService = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $authService = new \Zend\Authentication\AuthenticationService();
     if (!trim($username) || !trim($password)) {
         // clear identity anyway
         $authService->clearIdentity();
         return $this->redirect()->toRoute('application/child', array('controller' => 'signin', 'action' => 'index'));
     }
     $adapter = new \Zend\Authentication\Adapter\DbTable($adapterService, 'energy_user', 'username', 'passwd');
     $authService->setAdapter($adapter);
     $authService->getAdapter()->setIdentity($username)->setCredential($password);
     $result = $authService->authenticate();
     if ($result->isValid()) {
         $UserTable = $this->getServiceLocator()->get('Model\\Entity\\User');
         $UserData = $UserTable->getFinder()->setParams(array("where" => array("username" => $username)))->findOne();
         if ($UserData) {
             if ($UserData->status == User::ACTIVE) {
                 // now write auth into session, but not password
                 $UserData->passwd = NULL;
                 $UserData->auth_token = NULL;
                 $authService->getStorage()->write($UserData);
                 if ($authService->hasIdentity()) {
                     // type must be a valid type to login
                     switch ($UserData->user_type) {
                         case User::SU:
                             $this->flashMessenger()->addMessage(array('success' => 'Logged in as Super User.'));
                             return $this->redirect()->toRoute('su');
                         case User::CUSTOMER:
                             $this->flashMessenger()->addMessage(array('success' => 'You are successfully logged in.'));
                             return $this->redirect()->toRoute('user');
                         case 'default':
                             $this->flashMessenger()->addMessage(array('error' => 'Cannot Identify User.'));
                     }
                 } else {
                     $this->flashMessenger()->addMessage(array('error' => 'Server error occurred.'));
                 }
             } else {
                 $this->flashMessenger()->addMessage(array('error' => 'Cannot Login. Please check account status.'));
             }
         }
     } else {
         $this->flashMessenger()->addMessage(array('error' => 'Invalid Username/Password'));
     }
     // clear identity, just in case of bug
     $authService->clearIdentity();
     return $this->redirect()->toRoute('application/child', array('controller' => 'signin', 'action' => 'quit'));
 }
Example #2
0
 public function __invoke()
 {
     $authService = new \Zend\Authentication\AuthenticationService();
     return $authService->getStorage()->read()['user'];
 }
Example #3
0
         if (strlen($_REQUEST['password']) < 3) {
             $control->addValidationMessage('password_register', 'La password deve avere almeno tre caratteri');
         }
         if ($_REQUEST['password'] !== $_REQUEST['passwordr']) {
             $control->addValidationMessage('password_register', 'Le due password non coincidono');
         }
         if ($control->formIsValid()) {
             $user = \login\user\LoginInstantiator::getLoginInstance($db, $_REQUEST['username']);
             if (is_object($user) && $user->getData('username') != '') {
                 $control->addValidationMessage('username_register', 'Utente già registrato');
             }
         }
     } else {
         $user = \login\user\LoginInstantiator::createLoginInstance($db, $_REQUEST['username'], $_REQUEST['password']);
     }
     $auth->getStorage()->clear();
     if (is_numeric(session_id())) {
         session_destroy();
     }
 } else {
     if (array_key_exists('confirmCode', $_REQUEST)) {
         $_REQUEST['task'] = 'confirm';
         try {
             $user = \login\user\LoginInstantiator::confirmLoginInstance($db, $_REQUEST['confirmCode']);
         } catch (\Exception $e) {
             switch ($e->getCode()) {
                 case 1409011509:
                     $control->addValidationMessage('username_register', 'Utente non identificato');
                     break;
                 case 1409011510:
                     $control->addValidationMessage('username_register', 'Utente già autenticato');
 public function index04Action()
 {
     $adapter = $this->getServiceLocator()->get("db_books");
     $dbTableAdapter = new \Zend\Authentication\Adapter\DbTable($adapter, "user", "email", "fullname");
     //	$select = $dbTableAdapter->getDbSelect();
     $authenticateObj = new \Zend\Authentication\AuthenticationService(null, $dbTableAdapter);
     $authenticateObj->getAdapter()->setIdentity("*****@*****.**");
     $authenticateObj->getAdapter()->setCredential("Stark");
     $select = $authenticateObj->getAdapter()->getDbSelect();
     $select->where->equalTo("status", "0");
     //authen
     $result = $authenticateObj->authenticate();
     if (!$result->isValid()) {
         echo "<pre style='font-weight:bold'>";
         print_r($result->getMessages());
         echo "</pre>";
     } else {
         echo "good";
         //thêm nhiều column
         //$data = $authenticateObj->getAdapter()->getResultRowObject();
         $data = $dbTableAdapter->getResultRowObject();
         //agr 1:chọn column muốn lấy  ,agr 2 :chọn column không muốn lấy
         //ghi thông tin vào session
         $authenticateObj->getStorage()->write($data);
         echo "<pre style='font-weight:bold'>";
         print_r($data);
         echo "</pre>";
     }
     return false;
 }