function coreAuth(&$adapter, &$authService) { $dbAdapter = new \Zend\Db\Adapter\Adapter(array('driver' => 'Pdo', 'username' => 'kevin', 'password' => '123456', 'dsn' => 'mysql:dbname=bd_grupos;host=192.168.1.50', 'driver_options' => array())); $adapter = new \Zend\Authentication\AuthenticationService(); $authService = new \Zend\Authentication\Adapter\DbTable($dbAdapter, 'ta_usuario', 'va_nombre', 'va_contrasena'); $adapter->setStorage(new \Zend\Authentication\Storage\Session('Auth')); $adapter->setAdapter($authService); }
/** * * @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')); }
public function getServiceConfig() { return array('factories' => array('auth-storage' => function ($sm) { return new \Sticks\Storage\Auth('user_auth'); }, 'auth-service' => function ($sm) { $doctrineAdapter = $adapter = new \Custom\Auth\Adapter\Doctrine(null, '\\Sticks\\Model\\User', 'email', 'password', 'md5'); $authService = new \Zend\Authentication\AuthenticationService(); $authService->setAdapter($doctrineAdapter); $authService->setStorage($sm->get('auth-storage')); //$authService->setStorage(new \Zend\Authentication\Storage\Session('vasabi-auth')); return $authService; }, 'user-session' => function ($sm) { })); }
public function index02Action() { $adapter = $this->getServiceLocator()->get("db_books"); $dbTableAdapter = new \Zend\Authentication\Adapter\DbTable($adapter, "user", "email", "fullname"); //nhận kết quả trả về từ FORM -để kiểm tra với email va fullname $dbTableAdapter->setIdentity("*****@*****.**"); $dbTableAdapter->setCredential("Stark"); $authenticateObj = new \Zend\Authentication\AuthenticationService(); $authenticateObj->setAdapter($dbTableAdapter); //authen $result = $authenticateObj->authenticate(); if (!$result->isValid()) { echo "<pre style='font-weight:bold'>"; print_r($result->getMessages()); echo "</pre>"; } else { echo "good"; } return false; }
/** * Registers Slim Auth services on the given container. * * @param Container $pimple A container instance */ public function register(Container $pimple) { // This must be set to true or Slim Auth will not work. // @see https://github.com/marcelbonnet/slim-auth/issues/37 $pimple['settings']['determineRouteBeforeAppMiddleware'] = true; $pimple['auth'] = function ($c) { $auth = new \Zend\Authentication\AuthenticationService(); $auth->setAdapter($c->get('authAdapter')); if ($c->has('authStorage')) { $auth->setStorage($c->get('authStorage')); } return $auth; }; $pimple['redirectHandler'] = function ($c) { $redirectNotAuthenticated = '/login'; $redirectNotAuthorized = '/403'; if (isset($c['redirectNotAuthenticated'])) { $redirectNotAuthenticated = $c['redirectNotAuthenticated']; } if (isset($c['redirectNotAuthorized'])) { $redirectNotAuthorized = $c['redirectNotAuthorized']; } return new \marcelbonnet\Slim\Auth\Handlers\RedirectHandler($redirectNotAuthenticated, $redirectNotAuthorized); }; $pimple['throwHttpExceptionHandler'] = function ($c) { return new \marcelbonnet\Slim\Auth\Handlers\ThrowHttpExceptionHandler(); }; $pimple['slimAuthRedirectMiddleware'] = function ($c) { return new \marcelbonnet\Slim\Auth\Middleware\Authorization($c->get('auth'), $c->get('acl'), $c->get('redirectHandler')); }; $pimple['slimAuthThrowHttpExceptionMiddleware'] = function ($c) { return new \marcelbonnet\Slim\Auth\Middleware\Authorization($c->get('auth'), $c->get('acl'), $c->get('throwHttpExceptionHandler')); }; $pimple['authenticator'] = function ($c) { return new \marcelbonnet\Slim\Auth\Authenticator($c->get('auth')); }; }