Commit d50a5a9e24d742a98fb879914a8d4a9f2cb47d14

Authored by Brad Shuttleworth
1 parent 151e7a29

Patch from Bryn Divey (bryn@jamwarehouse.com)

- preferences handle name-failure more gracefully.
- permissions needed require_once
- add more detail to the dispatchervalidation around email, title.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4603 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/validation/dispatchervalidation.inc.php
... ... @@ -186,11 +186,13 @@ class KTDispatcherValidation {
186 186  
187 187 function validateFile($aFile, $aOptions = null) {
188 188 $bError = false;
189   - if (strlen($aFile['name']) == 0) {
  189 +
  190 + if (strlen(trim($aFile['name'])) == 0) {
190 191 $bError = true;
191 192 } else {
192 193 $bError = KTUtil::arrayGet($aFile, 'error');
193 194 }
  195 +
194 196 if ($bError) {
195 197 $message = _("You did not select a valid document to upload");
196 198  
... ... @@ -273,6 +275,24 @@ class KTDispatcherValidation {
273 275 }
274 276 return $oEntity;
275 277 }
  278 +
  279 +
  280 +
  281 +
  282 +
  283 + /* unlike the KTEmail version, this only handles ONE email address */
  284 + function validateEmailAddress($sEmailAddress, $aOptions = null) {
  285 + $sEmailAddress = trim($sEmailAddress);
  286 +
  287 + if (!ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $sEmailAddress )) {
  288 + $aOptions['message'] = KTUtil::arrayGet($aOptions,
  289 + 'message',
  290 + _("An invalid email address was given"));
  291 + $this->handleError($aOptions);
  292 + }
  293 + return $sEmailAddress;
  294 + }
  295 +
276 296 }
277 297  
278 298 ?>
... ...
plugins/ktcore/admin/managePermissions.php
... ... @@ -4,6 +4,7 @@ require_once(KT_LIB_DIR . "/templating/templating.inc.php");
4 4 require_once(KT_LIB_DIR . "/permissions/permission.inc.php");
5 5 require_once(KT_LIB_DIR . "/dispatcher.inc.php");
6 6 require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
  7 +require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
7 8  
8 9 class ManagePermissionsDispatcher extends KTAdminDispatcher {
9 10 function do_main() {
... ...
plugins/ktcore/folder/addDocument.php
... ... @@ -42,6 +42,7 @@ class KTFolderAddDocumentAction extends KTFolderAction {
42 42 $add_fields = array();
43 43 $add_fields[] = new KTFileUploadWidget(_('File'), _('The contents of the document to be added to the document management system.'), 'file', "", $this->oPage, true);
44 44 $add_fields[] = new KTStringWidget(_('Title'), _('The document title is used as the main name of a document through the KnowledgeTree.'), 'title', "", $this->oPage, true);
  45 +
45 46  
46 47 $aVocab = array();
47 48 foreach (DocumentType::getList() as $oDocumentType) {
... ... @@ -83,7 +84,9 @@ class KTFolderAddDocumentAction extends KTFolderAction {
83 84 $aErrorOptions = array(
84 85 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
85 86 );
  87 +
86 88 $aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions);
  89 + $sTitle = $this->oValidator->validateString($_REQUEST['title'], $aErrorOptions);
87 90  
88 91 $matches = array();
89 92 $aFields = array();
... ... @@ -99,7 +102,7 @@ class KTFolderAddDocumentAction extends KTFolderAction {
99 102 'contents' => new KTFSFileLike($aFile['tmp_name']),
100 103 'documenttype' => $this->oDocumentType,
101 104 'metadata' => $aFields,
102   - 'description' => $_REQUEST['title'],
  105 + 'description' => $sTitle,
103 106 );
104 107  
105 108 $mpo->start();
... ...
preferences.php
... ... @@ -10,8 +10,6 @@ require_once(KT_LIB_DIR . "/dispatcher.inc.php");
10 10  
11 11 require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
12 12  
13   -
14   -
15 13 class PreferencesDispatcher extends KTStandardDispatcher {
16 14 var $sSection = 'preferences';
17 15  
... ... @@ -111,14 +109,18 @@ class PreferencesDispatcher extends KTStandardDispatcher {
111 109  
112 110  
113 111 function do_updatePreferences() {
  112 + $aErrorOptions = array(
  113 + 'redirect_to' => array('main'),
  114 + );
  115 +
114 116 $oUser =& $this->oUser;
115 117  
116   - $name = KTUtil::arrayGet($_REQUEST, 'name');
117   - if (empty($name)) {
118   - $this->errorRedirectToMain(_('You must specify your name.'));
119   - }
  118 + $name = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'name'),
  119 + KTUtil::meldOptions($aErrorOptions, array('message' => _('You must specify your name.'))));
120 120  
121   - $email_address = KTUtil::arrayGet($_REQUEST, 'email_address');
  121 + $email_address = $this->oValidator->validateEmailAddress(KTUtil::arrayGet($_REQUEST, 'email_address'),
  122 + $aErrorOptions);
  123 +
122 124 $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false);
123 125 if ($email_notifications !== false) $email_notifications = true;
124 126 $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number');
... ...