adminadduseraction.class.php
查看本檔案說明文件.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/data/validator/passwordvalidator.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/view/admin/adminadduserview.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/view/admin/adminsiteuserslistview.class.php" );
00013
00020 class AdminAddUserAction extends SiteAdminAction
00021 {
00022
00023 var $_userName;
00024 var $_userPassword;
00025 var $_userEmail;
00026 var $_userBlog;
00027 var $_userFullName;
00028 var $_properties;
00029 var $_userStatus;
00030
00031 function AdminAddUserAction( $actionInfo, $request )
00032 {
00033 $this->SiteAdminAction( $actionInfo, $request );
00034
00035
00036 $this->registerFieldValidator( "userName", new UsernameValidator());
00037 $this->registerFieldValidator( "newUserPassword", new PasswordValidator());
00038 $this->registerFieldValidator( "userEmail", new EmailValidator());
00039 $this->registerFieldValidator( "userStatus", new IntegerValidator());
00040 $this->registerField( "userFullName" );
00041 $this->registerField( "userBlog", new IntegerValidator());
00042 $view = new AdminAddUserView( $this->_blogInfo );
00043 $this->setValidationErrorView( $view );
00044 }
00045
00046 function perform()
00047 {
00048
00049 $this->_userName = Textfilter::filterAllHTML($this->_request->getValue( "userName" ));
00050 $this->_userPassword = $this->_request->getValue( "newUserPassword" );
00051 $this->_userEmail = Textfilter::filterAllHTML($this->_request->getValue( "userEmail" ));
00052 $this->_userFullName = Textfilter::filterAllHTML($this->_request->getValue( "userFullName" ));
00053 $this->_userStatus = $this->_request->getValue( "userStatus" );
00054 $this->_userBlog = $this->_request->getValue( "userBlog" );
00055
00056
00057
00058 $users = new Users();
00059 $userInfo = $users->userExists( $this->_userName );
00060 if( $userInfo ) {
00061 $this->_form->setFieldValidationStatus( "userName", false );
00062 $this->_view = new AdminAddUserView( $this->_blogInfo );
00063 $this->setCommonData( true );
00064 return false;
00065 }
00066
00067
00068 $user = new UserInfo( $this->_userName,
00069 $this->_userPassword,
00070 $this->_userEmail,
00071 "",
00072 $this->_userFullName,
00073 0,
00074 $this->_properties );
00075 $user->setStatus( $this->_userStatus );
00076 $this->notifyEvent( EVENT_PRE_USER_ADD, Array( "user" => &$user ));
00077 $newUserId = $users->addUser( $user );
00078
00079 if( !$newUserId ) {
00080 $this->_view = new AdminAddUserView( $this->_blogInfo );
00081 $this->_form->setFieldValidationStatus( "userName", false );
00082 $this->setCommonData( true );
00083 return false;
00084 }
00085
00086
00087
00088 if( $this->_userBlog > 0 ) {
00089 $permissions = new UserPermissions();
00090 $result = $permissions->grantPermission( $newUserId, $this->_userBlog, PERMISSION_BLOG_USER );
00091 }
00092
00093 $this->notifyEvent( EVENT_POST_USER_ADD, Array( "user" => &$user ));
00094
00095 $this->_view = new AdminSiteUsersListView( $this->_blogInfo );
00096 $this->_view->setSuccessMessage( $this->_locale->pr("user_added_ok", $user->getUsername()));
00097 $this->setCommonData();
00098
00099 return true;
00100 }
00101 }
00102 ?>