[ 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/ -> adminadduseraction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/data/validator/passwordvalidator.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );    
   9      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );    
  12      lt_include( PLOG_CLASS_PATH."class/view/admin/adminadduserview.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/view/admin/adminsiteuserslistview.class.php" );    
  14  
  15      /**
  16       * \ingroup Action
  17       * @private
  18       *
  19       * Adds a new user to the database.
  20       */
  21      class AdminAddUserAction extends AdminAction 
  22      {
  23  
  24          var $_userName;
  25          var $_userPassword;
  26          var $_userEmail;
  27          var $_userBlog;
  28          var $_userFullName;
  29          var $_properties;
  30          var $_userStatus;
  31          var $_permissions;
  32  
  33      	function AdminAddUserAction( $actionInfo, $request )
  34          {
  35              $this->AdminAction( $actionInfo, $request );
  36              
  37              // for data validation purposes
  38              $this->registerFieldValidator( "userName", new UsernameValidator());
  39              $this->registerFieldValidator( "newUserPassword", new PasswordValidator());
  40              $this->registerFieldValidator( "userEmail", new EmailValidator());
  41              $this->registerFieldValidator( "userStatus", new IntegerValidator());
  42              $this->registerField( "userFullName" );
  43              $this->registerFieldValidator( "blogId", new IntegerValidator(), true );
  44              $this->registerField( "blogName" );
  45              $this->registerField( "userPermissions" );
  46              $view = new AdminAddUserView( $this->_blogInfo );
  47              $view->setErrorMessage( $this->_locale->tr("error_adding_user" ));
  48              $this->setValidationErrorView( $view );
  49  
  50              $this->requireAdminPermission( "add_user" );
  51          }
  52  
  53          function perform()
  54          {
  55              // fetch the validated data
  56              $this->_userName = Textfilter::filterAllHTML($this->_request->getValue( "userName" ));
  57              $this->_userPassword = $this->_request->getValue( "newUserPassword" );
  58              $this->_userEmail = Textfilter::filterAllHTML($this->_request->getValue( "userEmail" ));
  59              $this->_userFullName = Textfilter::filterAllHTML($this->_request->getValue( "userFullName" ));
  60              $this->_userStatus = $this->_request->getValue( "userStatus" );
  61              $this->_userBlog = $this->_request->getValue( "blogId" );
  62              $this->_permissions = $this->_request->getValue( "userPermissions" );
  63              
  64              // now that we have validated the data, we can proceed to create the user, making
  65              // sure that it doesn't already exists
  66              $users = new Users();
  67              $userInfo = $users->getUserInfoFromUsername( $this->_userName );
  68              if( $userInfo ) {
  69                  $this->_form->setFieldValidationStatus( "userName", false );                
  70                  $this->_view = new AdminAddUserView( $this->_blogInfo );
  71                  $this->setCommonData( true );
  72                  return false;
  73              }
  74  
  75              // otherwise, we can create a new one
  76              $user = new UserInfo( $this->_userName, 
  77                                    $this->_userPassword, 
  78                                    $this->_userEmail, 
  79                                    "", 
  80                                    $this->_userFullName,
  81                                    0,
  82                                    $this->_properties );
  83              $user->setStatus( $this->_userStatus );
  84              $this->notifyEvent( EVENT_PRE_USER_ADD, Array( "user" => &$user ));
  85              $newUserId = $users->addUser( $user );
  86              
  87              if( !$newUserId ) {
  88                  $this->_view = new AdminAddUserView( $this->_blogInfo );
  89                  $this->_form->setFieldValidationStatus( "userName", false );
  90                  $this->setCommonData( true );
  91                  return false;
  92              }
  93  
  94              // grant the site-wide permissions, if any granted
  95              $userPerms = new UserPermissions();
  96              if( is_array( $this->_permissions )) {
  97                  foreach( $this->_permissions as $val => $permId ) {
  98                      $perm = new UserPermission( $user->getId(), 0, $permId );
  99                      $res = $userPerms->grantPermission( $perm );
 100                  }
 101              }            
 102              
 103              // if the userBlog parameter is different than 0, we should somehow allow the user
 104              // to log into that blog although he/she won't have much to do with only the
 105              // blog_access permission
 106              if( $this->_userBlog > 0 ) {
 107                  $perms = new Permissions();
 108                  $blogAccess = $perms->getPermissionByName( "blog_access" );
 109                  $perm = new UserPermission( $newUserId, $this->_userBlog, $blogAccess->getId() );
 110                  $result = $userPerms->grantPermission( $perm );
 111              }
 112              
 113              $this->notifyEvent( EVENT_POST_USER_ADD, Array( "user" => &$user ));
 114  
 115              if( !$this->userHasPermission( "view_users", 0 ))
 116                  $this->_view = new AdminAddUserView( $this->_blogInfo );
 117              else
 118                  $this->_view = new AdminSiteUsersListView( $this->_blogInfo );
 119  
 120              $this->_view->setSuccessMessage( $this->_locale->pr("user_added_ok", $user->getUsername()));
 121              $this->setCommonData();
 122  
 123              return true;
 124          }
 125      }
 126  ?>


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