Skip to content

Instantly share code, notes, and snippets.

@apoca
Created March 5, 2014 18:26
Show Gist options
  • Save apoca/9373397 to your computer and use it in GitHub Desktop.
Save apoca/9373397 to your computer and use it in GitHub Desktop.
My controller Login:
public function authenticateAction()
{
$request = $this->getRequest();
if ($request->isPost()){
$params = $request->getPost()->toArray();
//check authentication...
$username = $request->getPost('npo-login-email');
$password = $request->getPost('npo-login-pw');
$rememberme = $request->getPost('npo-login-rememberme');
$this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password);
$result = $this->getAuthService()->authenticate();
foreach($result->getMessages() as $message)
{
//save message temporary into flashmessenger
$this->flashMessenger()->addSuccessMessage($this->getServiceLocator()
->get('translator')
->translate($message));
}
if ($result->isValid()) {
//check if it has rememberMe :
if ($rememberme == 1) {
$this->getSessionStorage()
->setRememberMe(1);
//set storage again
$this->getAuthService()->setStorage($this->getSessionStorage());
}
$this->getAuthService()->getStorage()->write($username);
$result = new JsonModel(array(
'next_url' => '/wall/ok',
'message' => $this->flashMessenger()->getMessages(),
'success' => false,
));
} else {
$result = new JsonModel(array(
'next_url' => '/auth/login',
'message' => $this->flashMessenger()->getMessages(),
'success' => false,
));
}
}
return $result;
}
// My MODULE Factories
'Application\Model\AuthStorage' => function ($sm)
{
return new \Application\Model\AuthStorage('user_esolidar');
},
'AuthService' => function ($sm)
{
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$authStorage = $sm->get('Application\Model\AuthStorage');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'user', 'email', 'password', 'SHA1(?)');
$authService = new AuthenticationService();
$authService->setAdapter($dbTableAuthAdapter);
$authService->setStorage($authStorage);
return $authService;
},
// THE ERROR:
<br />
<b>Fatal error</b>: Call to a member function getAdapter() on a non-object in <b>/usr/local/zend/var/apps/http/esolidar.bewarket.setima.local/80/0.1/module/Application/src/Application/Controller/AjaxController.php</b> on line <b>285</b><br />
is in this line:
$this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment