Add input validation to admin pages
This commit is contained in:
@@ -10,7 +10,7 @@ if ( ! $auth->isAuthenticated() || ! $auth->hasPermission(StatusBoard_Permission
|
||||
}
|
||||
|
||||
$activity = null;
|
||||
$success = true;
|
||||
$messages = array();
|
||||
|
||||
$service_id = $request->get('id', 'Sihnon_Exception_InvalidParameters');
|
||||
$service = null;
|
||||
@@ -28,34 +28,43 @@ if ($request->exists('do')) {
|
||||
$name = StatusBoard_Main::issetelse($_POST['name'], 'Sihnon_Exception_InvalidParameters');
|
||||
$description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters');
|
||||
|
||||
if ($name) {
|
||||
try {
|
||||
StatusBoard_Validation_Text::length($name, 1, 255);
|
||||
|
||||
$service->name = $name;
|
||||
}
|
||||
if ($description) {
|
||||
$service->description = $description;
|
||||
}
|
||||
if ($name || $description) {
|
||||
$service->save();
|
||||
$messages[] = array(
|
||||
'severity' => 'success',
|
||||
'content' => 'The service was updated succesfully.',
|
||||
);
|
||||
} else {
|
||||
$messages[] = 'No changes were necessary.';
|
||||
}
|
||||
|
||||
} catch (StatusBoard_Exception_InvalidContent $e) {
|
||||
$messages[] = array(
|
||||
'severity' => 'error',
|
||||
'content' => 'The service was not modified due to invalid parameters being passed.',
|
||||
);
|
||||
}
|
||||
} break;
|
||||
|
||||
case 'add-site': {
|
||||
$name = StatusBoard_Main::issetelse($_POST['name'], 'Sihnon_Exception_InvalidParameters');
|
||||
$description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters');
|
||||
|
||||
$site = $service->newSite($name, $description);
|
||||
|
||||
$messages[] = array(
|
||||
'severity' => 'success',
|
||||
'content' => 'The site was created succesfully.',
|
||||
);
|
||||
try {
|
||||
StatusBoard_Validation_Text::length($name, 1, 255);
|
||||
|
||||
$site = $service->newSite($name, $description);
|
||||
|
||||
$messages[] = array(
|
||||
'severity' => 'success',
|
||||
'content' => 'The site was created succesfully.',
|
||||
);
|
||||
} catch (StatusBoard_Exception_InvalidContent $e) {
|
||||
$messages[] = array(
|
||||
'severity' => 'error',
|
||||
'content' => 'The site was not added due to invalid parameters being passed.',
|
||||
);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user