Created
September 29, 2012 23:12
-
-
Save microlancer/3805400 to your computer and use it in GitHub Desktop.
Problem with Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Zend Framework (http://framework.zend.com/) | |
* | |
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository | |
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | |
* @license http://framework.zend.com/license/new-bsd New BSD License | |
*/ | |
namespace Application\Controller; | |
use Zend\Mvc\Controller\AbstractActionController; | |
use Zend\View\Model\ViewModel; | |
use Zend\Authentication\AuthenticationService; | |
use Zend\Authentication\Storage\Session as SessionStorage; | |
use Zend\Authentication\Adapter\DbTable as AuthAdapter; | |
use Zend\Db\Adapter as DbAdapter; | |
class IndexController extends AbstractActionController | |
{ | |
public function indexAction() | |
{ | |
return new ViewModel(); | |
} | |
public function loginAction() | |
{ | |
$email = 'test';//$this->getRequest()->getMetadata('email'); | |
$password = 'password';//$this->getRequest()->getMetadata('password'); | |
$auth = new AuthenticationService(); | |
$auth->setStorage(new SessionStorage()); | |
$sm = $this->getServiceLocator(); | |
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); // Giving me: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter | |
$authAdapter = new AuthAdapter($dbAdapter); | |
$authAdapter->setTableName('accounts') | |
->setIdentityColumn('email') | |
->setCredentialColumn('password') | |
->setIdentity($email) | |
->setCredential($password); | |
$select = $authAdapter->getDbSelect(); | |
$select->where('status != "deleted"'); | |
$result = $auth->authenticate($authAdapter); | |
var_dump($result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment