Source for file UserController.php

Documentation is available at UserController.php

  1. <?php
  2. /**
  3.  * Controller class for managing user actions.
  4.  * 
  5.  * @author Margus Sellin <margus@bitweb.ee>
  6.  * @copyright Copyright (C) 2011. All rights reserved. Margus Sellin
  7.  * @project olymp
  8.  * 
  9.  */
  10. class UserController extends Zend_Controller_Action
  11. {
  12.     /**
  13.      * Login action.
  14.      * User inserts his/her username and password into form and based on
  15.      * their validity he/she is being logged in or informed with the error
  16.      * message.
  17.      */
  18.     public function loginAction()
  19.     {
  20.         $form new Form_User();
  21.         $this->view->form $form;
  22.  
  23.         if($this->_request->isPost()) {
  24.             if($form->isValid($this->_request->getPost())) {
  25.                 $username $this->_getParam('username');
  26.                 $password $this->_getParam('password');
  27.  
  28.                 $isValid $this->authenticate($username$password);
  29.                 
  30.                 if($isValid{
  31.                     $this->_helper->redirector('index''admin');
  32.                 }
  33.             }
  34.                $this->view->error 'Sisselogimine ebaõnnestus. Palun kontrollige andmeid.';
  35.         
  36.         
  37.     }
  38.     
  39.     /**
  40.      * Authentication action.
  41.      * Verifies whether the parameters given by the user are valid or not by
  42.      * checking their existance in database.
  43.      * 
  44.      * @access public
  45.      * @param string $username User's username
  46.      * @param string $password User's password
  47.      * @return boolean $isValid Authentication result
  48.      */
  49.     
  50.     private function authenticate($username$password{
  51.         $modelUser new Model_User();
  52.         $auth Zend_Auth::getInstance();
  53.         $dbAdapter $modelUser->getAdapter();
  54.         
  55.         $authAdapter new Zend_Auth_Adapter_DbTable($dbAdapter);
  56.         $authAdapter->setTableName('kasutaja')
  57.                     ->setIdentityColumn('Kasutajanimi')
  58.                     ->setCredentialColumn('Parool');
  59.         
  60.         $authAdapter->setIdentity($username);
  61.         $authAdapter->setCredential(md5($password));
  62.         
  63.         $result $auth->authenticate($authAdapter);
  64.         $isValid $result->isValid();
  65.         
  66.         if ($isValid{
  67.             $userData $modelUser->fetchRow('Kasutajanimi=' $dbAdapter->quote($username));
  68.             $auth->getStorage()->write($userData);
  69.         }
  70.         
  71.         return $isValid;
  72.     }
  73.     
  74.     /**
  75.      * Logout action.
  76.      * Logs out the current user by clearing his/her identity in Zend_Auth instance.
  77.      */
  78.     
  79.     public function logoutAction()
  80.     {
  81.         $auth Zend_Auth::getInstance();
  82.         $auth->clearIdentity();
  83.         
  84.         $this->_helper->redirector('index''index');
  85.     }
  86. }

Documentation generated on Tue, 14 Jun 2011 16:02:28 +0300 by phpDocumentor 1.4.1