Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //application/controllers/AuthController.php
- <?php
- class AuthController extends Zend_Controller_Action
- {
- public function loginAction(){
- $db = $this->_getParam('db');
- $loginForm = new Default_Form_Auth_Login();
- if($loginForm->isValid($_POST)) {
- $adapter = new Zend_Auth_Adapter_DbTable(
- $db,
- 'users',
- 'username',
- 'password',
- 'MD5(CONCAT(?, password_salt))'
- );
- $adapter->setIdentity($loginForm->getValue('username'));
- $adapter->setCredential($loginForm->getValue('password'));
- $auth = Zend_Auth::getInstance();
- $result = $auth->authenticate($adapter);
- if($result->isValid()) {
- $this->_helper->FlashMessenger('Successful Login');
- $this->redirect('/');
- return;
- }
- }
- $this->view->loginForm = $loginForm;
- }
- }
- //application/forms/Auth/Login.php
- <?php
- class Default_Form_Auth_Login extends Zend_Form
- {
- public function init(){
- $this->setMethod('post');
- $this->addElement(
- 'text', 'username', array(
- 'label' => 'Username:',
- 'required' => true,
- 'filters' => array('StringTrim'),
- )
- );
- $this->addElement(
- 'password', 'password', array(
- 'label' => 'Password:',
- 'required' => true,
- )
- );
- $this->addElement(
- 'submit', 'submit', array(
- 'ignore' => true,
- 'label' => 'Login',
- )
- );
- }
- }
Add Comment
Please, Sign In to add comment