Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form
- <?php
- class App_Form_Login extends Zend_Form
- {
- public function __construct()
- {
- parent::__construct($options);
- $this->setName('UserLogin');
- $username = new Zend_Form_Element_Text('username');
- $username->setLabel('User Name')
- ->setRequired(true)
- ->addFilter('StripTags')
- ->addFilter('StringTrim')
- ->addValidator('NotEmpty');
- $pass = new Zend_Form_Element_Password('pass');
- $pass->setLabel('Password')
- ->setRequired(true)
- ->addFilter('StripTags')
- ->addFilter('StringTrim')
- ->addValidator('NotEmpty');
- $submit = new Zend_Form_Element_Submit('submit');
- $redirect = new Zend_Form_Element_Hidden('redirect');
- $submit->setAttrib('id', 'submitbutton');
- $this->addElements( array ( $username, $pass, $submit));
- }
- }
- controller
- <?php
- class IndexController extends Zend_Controller_Action {
- public function init() {
- }
- public function indexAction() {
- $this->view->mainourbank='yes';
- }
- public function loginAction() {
- $this->_helper->layout->disableLayout();
- $loginForm = new App_Form_Login();
- $redirect = $this->getRequest()->getParam('redirect', 'index/view');
- $loginForm->setAttrib('redirect', $redirect );
- $auth = Zend_Auth::getInstance();
- if(Zend_Auth::getInstance()->hasIdentity()) {
- $this->_redirect('/index/view');
- } else if ($this->getRequest()->isPost()) {
- if ( $loginForm->isValid($this->getRequest()->getPost()) ) {
- $username = $this->getRequest()->getPost('username');
- $pwd = $this->getRequest()->getPost('pass');
- $authAdapter = new App_Model_AuthAdapter($username, $pwd);
- $result = $auth->authenticate($authAdapter);
- if(!$result->isValid()) {
- switch ($result->getCode()) {
- case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
- $this->view->error = 'user credentials not found';
- }
- } else {
- // $tre = new Acl($username,$pwd);
- $this->_redirect( $redirect );
- }
- }
- }
- $this->view->loginForm = $loginForm;
- }
- public function viewAction() {
- }
- public function logoutAction() {
- $auth = Zend_Auth::getInstance();
- $auth->clearIdentity();
- $this->_redirect('/');
- }
- }
- model
- <?php
- class App_Model_Users extends Zend_Db_Table_Abstract
- {
- /*
- * @var $_name table name : users
- */
- protected $_name = 'ourbank_userloginupdates';
- public function findCredentials($username, $pwd)
- {
- $select = $this->select()
- ->setIntegrityCheck(false)
- ->join(array('u' => 'ourbank_userloginupdates'),array('user_id'))
- ->where('u.login_name = ?', $username)
- ->where('u.password = ?',$pwd)
- ->join(array('g'=>'ourbank_usergrants'),'u.user_id = g.user_id')
- ->join(array('r' =>'ourbank_grant'),'r.grant_id = g.grant_id')
- ->join(array('a' =>'ourbank_grantactivites'),'a.grant_id = r.grant_id')
- ->join(array('c' =>'ourbank_activity'),'c.activity_id = a.activity_id');
- $result= $this->fetchRow($select);
- // print_r($result);
- // print_r($result);
- // return($result);
- // return $result->toArray();
- // print_r($result);
- if($row) {
- /*
- * If success return the row
- */
- return $row;
- }
- return false;
- // }
- }
- }
Add Comment
Please, Sign In to add comment