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

Documentation generated on Wed, 15 Jun 2011 15:50:40 +0300 by phpDocumentor 1.4.1