[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/admin/ -> adminloginaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/action.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/admin/admindashboardview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/admindefaultview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/net/http/session/sessioninfo.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/misc/version.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/view/admin/adminnewpostview.class.php" );
  14  
  15      /**
  16       * \ingroup Action
  17       * @private
  18       *
  19       * When the user fills in the login form, we jump to this action which will show
  20       * another form when the user will choose to which of the blog he or she wants to
  21       * carry out administrative tasks.
  22       */
  23      class AdminLoginAction extends Action 
  24      {
  25  
  26          var $_userName;
  27          var $_userPassword;
  28          var $_op;
  29          var $_locale;
  30  
  31          /**
  32           * Constructor. If nothing else, it also has to call the constructor of the parent
  33           * class, BlogAction with the same parameters
  34           */
  35          function AdminLoginAction( $actionInfo, $request )
  36          {
  37              $this->Action( $actionInfo, $request );
  38  
  39              $this->_config =& Config::getConfig();
  40              $this->_locale =& Locales::getLocale( $this->_config->getValue( "default_locale" ));
  41  
  42              // data validation
  43              $this->registerFieldValidator( "userName", new StringValidator());
  44              $this->registerFieldValidator( "userPassword", new StringValidator());
  45              $view = new AdminDefaultView();
  46              $view->setErrorMessage( $this->_locale->tr("error_incorrect_username_or_password"));
  47              $this->setValidationErrorView( $view );
  48          }
  49  
  50          /**
  51           * Carries out the specified action
  52           */
  53          function perform()
  54          {
  55              // get the parameters, which have already been validated
  56              $this->_userName     = Textfilter::filterAllHTML($this->_request->getValue( "userName" ));
  57              $this->_userPassword = $this->_request->getValue( "userPassword" );
  58              $this->_op           = Textfilter::filterAllHTML($this->_request->getValue( "op" ));
  59  
  60              // create a plugin manager
  61              $pm =& PluginManager::getPluginManager();    
  62          
  63              // try to authenticate the user
  64              $users = new Users();
  65              if( !$users->authenticateUser( $this->_userName, $this->_userPassword )) {
  66                  $this->_view = new AdminDefaultView();
  67                  $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_username_or_password"));
  68                  $this->setCommonData();
  69                  
  70                  $pm->notifyEvent( EVENT_LOGIN_FAILURE, Array( "user" => $this->_userName ));
  71                  return false;
  72              }
  73              
  74              // if the user is correct, get and put his or her information in the session
  75              $userInfo = $users->getUserInfoFromUsername( $this->_userName );
  76              
  77              if( !$userInfo ) {
  78                  $this->_view = new AdminDefaultView();
  79                  $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_username_or_password"));
  80                  $this->setCommonData();
  81                  
  82                  $pm->notifyEvent( EVENT_LOGIN_FAILURE, Array( "user" => $this->_userName ));
  83                  return false;
  84              }
  85              
  86              // check if the user has the "login_perm" permission and is allowed to log in
  87              if( !$userInfo->hasPermissionByName( "login_perm" )) {
  88                  $this->_view = new AdminDefaultView();
  89                  $this->_view->setErrorMessage( $this->_locale->tr("error_cannot_login"));
  90                  $this->setCommonData();
  91                  
  92                  $pm->notifyEvent( EVENT_LOGIN_FAILURE, Array( "user" => $this->_userName ));
  93                  return false;
  94              }
  95              
  96              $pm->notifyEvent( EVENT_USER_LOADED, Array( "user" => &$userInfo, "from" => "Login" ));
  97  
  98              // get the list of blogs to which the user belongs
  99              $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
 100  
 101              // but if he or she does not belong to any yet, we quit
 102              if( empty($userBlogs)) {
 103                  $this->_view = new AdminDefaultView();
 104                  $this->_view->setErrorMessage( $this->_locale->tr("error_dont_belong_to_any_blog"));
 105                  $this->setCommonData();
 106  
 107                  return false;
 108              }
 109  
 110              // We have to update the userInfo in session after we check all situations
 111              $session = HttpVars::getSession();
 112              $sessionInfo = $session["SessionInfo"];
 113  
 114              $sessionInfo->setValue( "userInfo", $userInfo );
 115              $session["SessionInfo"] = $sessionInfo;
 116              HttpVars::setSession( $session );
 117              
 118              $pm->notifyEvent( EVENT_BLOGS_LOADED, Array( "blogs" => &$userBlogs, "from" => "Login" ));            
 119              
 120              // check if we are skipping the dashboard
 121              if( $this->_config->getValue( "skip_dashboard" )) {
 122                  // get the first blog that came
 123                  $this->_blogInfo = $userBlogs[0];
 124                  // set it in the session
 125                  $session = HttpVars::getSession();
 126                  $sessionInfo->setValue( "blogInfo", $this->_blogInfo );
 127                  $session["SessionInfo"] = $sessionInfo;
 128                  HttpVars::setSession( $session );            
 129                  // and then continue...
 130                  if( $userInfo->hasPermissionByName( "new_post", $this->_blogInfo->getId()))
 131                      AdminController::setForwardAction( "newPost" );
 132                  else
 133                      AdminController::setForwardAction( "Manage" );
 134              }
 135              else {
 136                  $this->_view = new AdminDashboardView( $userInfo, $userBlogs );    
 137              }
 138              // better to return true if everything's fine
 139              return true;
 140          }
 141      }
 142  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics