energine
[ class tree: energine ] [ index: energine ] [ all elements ]

Source for file LoginForm.class.php

Documentation is available at LoginForm.class.php

  1. <?php
  2. /**
  3.  * Содержит класс LoginForm
  4.  *
  5.  * @package energine
  6.  * @subpackage user
  7.  * @author dr.Pavka
  8.  * @copyright Energine 2006
  9.  * @version $Id$
  10.  */
  11.  
  12. //require_once('core/modules/share/components/DataSet.class.php');
  13.  
  14.  
  15. /**
  16.  * Вывод формы авторизации
  17.  *
  18.  * @package energine
  19.  * @subpackage user
  20.  * @author dr.Pavka
  21.  */
  22. class LoginForm extends DataSet {
  23.  
  24.  
  25.     /**
  26.      * Конструктор
  27.      *
  28.      * @param string $name 
  29.      * @param string $module 
  30.      */
  31.     public function __construct($name$moduleDocument $document,  array $params null{
  32.         $params['action'$document->user->isAuthenticated()?'showLogoutForm':'showLoginForm';
  33.         parent::__construct($name$module$document,  $params);
  34.         if (
  35.             $this->document->user->isAuthenticated(
  36.             && $this->document->user->isNowAuthenticated()
  37.             && ($this->getParam('successAction'!== false)
  38.         {
  39.             $this->response->redirectToCurrentSection($this->getParam('successAction'));
  40.         }
  41.         $this->setTitle($this->translate('TXT_LOGIN_FORM'));
  42.     }
  43.  
  44.     /**
  45.      * Добавлены:
  46.      * Параметр successAction - УРЛ на который происходит переадресация в случае успеха
  47.      *
  48.      * @return array 
  49.      * @access protected
  50.      */
  51.     protected function defineParams({
  52.         return array_merge(
  53.         parent::defineParams(),
  54.         array(
  55.         'successAction' => false
  56.         )
  57.         );
  58.     }
  59.  
  60.     /**
  61.      * Вывод формы авторизации
  62.      *
  63.      * @return type 
  64.      * @access public
  65.      */
  66.  
  67.     public function showLoginForm({
  68.         $this->prepare();
  69.         if (isset($_POST['user']['login'])) {
  70.             $messageField new FieldDescription('message');
  71.             $messageField->setType(FieldDescription::FIELD_TYPE_STRING);
  72.             $this->getDataDescription()->addFieldDescription($messageField);
  73.             $messageField->setRights(FieldDescription::FIELD_MODE_READ);
  74.  
  75.             $messageField new Field('message');
  76.             $messageField->addRowData($this->translate('ERR_BAD_LOGIN'));
  77.             $this->getData()->addField($messageField);
  78.         }
  79.     }
  80.  
  81.  
  82.     /**
  83.       * Вывод формы logout
  84.       *
  85.       * @return type 
  86.       * @access public
  87.       */
  88.  
  89.     public function showLogoutForm({
  90.         $request Request::getInstance();
  91.         //$this->setTitle($this->translate('TXT_LOGOUT'));
  92.         $this->addTranslation('TXT_USER_GREETING');
  93.         $this->addTranslation('TXT_USER_NAME');
  94.         $this->addTranslation('TXT_ROLE_TEXT');
  95.         $this->setDataSetAction($request->getBasePath()true);
  96.         $this->prepare();
  97.         foreach (UserGroup::getInstance()->getUserGroups($this->document->user->getID()) as $roleID{
  98.             $tmp UserGroup::getInstance()->getInfo($roleID);
  99.             $data[$tmp['group_name'];
  100.         }
  101.  
  102.         $this->getData()->getFieldByName('role_name')->setData(implode(', '$data));
  103.     }
  104.  
  105.     protected function loadData({
  106.         $result false;
  107.         switch ($this->getAction()) {
  108.             case 'showLogoutForm':
  109.                 foreach ($this->getDataDescription()->getFieldDescriptionList(as $fieldName{
  110.                     $result[array($fieldName=>$this->document->user->getValue($fieldName));
  111.                 }
  112.                 break;
  113.             default:
  114.                 $result parent::loadData();
  115.         }
  116.         return $result;
  117.     }
  118. }
В создании документации нам помог: phpDocumentor