Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IndexController extends Zend_Controller_Action
- {
- public function init()
- {
- /* Initialize action controller here */
- }
- public function indexAction()
- {
- // action body
- $form = new Default_Form_Login();
- $this->view->form = $form;
- $username = $this->_request->getParam('username');
- echo "<br>";
- $password = $this->_request->getParam('password');
- if ($username && $password) {
- // Save a reference to the Singleton instance of Zend_Auth
- $auth = Zend_Auth::getInstance();
- // Use 'someNamespace' instead of 'Zend_Auth'
- $auth->setStorage(new Zend_Auth_Storage_Session('user'));
- $dbAdapter = Zend_Db_Table::getDefaultAdapter();
- // Configure the instance with constructor parameters...
- $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
- $authAdapter->setTableName('users')
- ->setIdentityColumn('username')
- ->setCredentialColumn('password');
- $authAdapter->setIdentity($username)
- ->setCredential($password);
- $result = $auth->authenticate($authAdapter);
- switch ($result->getCode()) {
- case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
- echo '/ do stuff for nonexistent identity /';
- break;
- case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
- echo '/ do stuff for invalid credential /';
- break;
- case Zend_Auth_Result::SUCCESS:
- echo '/ do stuff for successful authentication /';
- $this->_redirect('/members');
- break;
- default:
- echo '/ do stuff for other failure /';
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment