/** * * @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')); }
<?php $manager = new \Zend\Session\SessionManager(); $manager->setName('abbrevia'); \Zend\Session\Container::setDefaultManager($manager); $auth = new Zend\Authentication\AuthenticationService(); $db->session = $manager->getStorage(); $facebookSession = new \Zend\Session\Container('facebook_id'); if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'login' && array_key_exists('xhrValidate', $_REQUEST) && array_key_exists('username', $_REQUEST) && array_key_exists('password', $_REQUEST)) { if (is_numeric(session_id())) { session_destroy(); } $authAdapter = new \login\Auth($db, $_REQUEST['username'], $_REQUEST['password']); $authResult = $auth->authenticate($authAdapter); if ($authResult->getCode() != \Zend\Authentication\Result::SUCCESS) { $control->addValidationMessage('username_login', 'Credenziali errate'); } $db->session->plain_pwd = $_REQUEST['password']; } else { if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'register' && array_key_exists('username', $_REQUEST) && array_key_exists('password', $_REQUEST)) { $_REQUEST['task'] = 'register'; if (array_key_exists('xhrValidate', $_REQUEST)) { if (!filter_var($_REQUEST['username'], FILTER_VALIDATE_EMAIL)) { $control->addValidationMessage('username_register', 'Inserisci una mail valida'); } 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'); }
/** * Authenticate the given username and password with LDAP. * * @param string $username * @param string $password * @return \Zend\Authentication\Result */ public function authenticate($username, $password) { $auth = new Zend\Authentication\AuthenticationService(); $adapter = new Zend\Authentication\Adapter\Ldap(array($this->config()->options), $username, $password); return $auth->authenticate($adapter); }
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; }