From 2ec2403ccec10d8e1684f766c66322061d6937e3 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Thu, 19 Mar 2015 17:32:02 -0400 Subject: [PATCH] Moved provisioning change function into controller from helper --- .../application/common/ProvisioningHelper.php | 27 +-------------- .../controllers/ProvisioningController.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/airtime_mvc/application/common/ProvisioningHelper.php b/airtime_mvc/application/common/ProvisioningHelper.php index a0b44392c..580c20e52 100644 --- a/airtime_mvc/application/common/ProvisioningHelper.php +++ b/airtime_mvc/application/common/ProvisioningHelper.php @@ -73,32 +73,6 @@ class ProvisioningHelper http_response_code(201); } - /** - * Endpoint to change Airtime preferences remotely. - * Mainly for use with the dashboard right now. - */ - public function changeAction() { - $apikey = $_SERVER['PHP_AUTH_USER']; - if (!isset($apikey) || $apikey != $this->apikey) { - Logging::info("Invalid API Key: $apikey"); - http_response_code(403); - echo "ERROR: Incorrect API key"; - return; - } - - try { - $this->parsePostParams(); - $this->initializePrefs(); - } catch (Exception $e) { - http_response_code(400); - Logging::error($e->getMessage()); - echo $e->getMessage() . PHP_EOL; - return; - } - - http_response_code(201); - } - /** * Check if the database settings and credentials given are valid * @return boolean true if the database given exists and the user is valid and can access it @@ -124,6 +98,7 @@ class ProvisioningHelper // Result is either boolean FALSE (no table found) or PDOStatement Object (table found) return $result !== FALSE; } + private function parsePostParams() { $this->dbuser = $_POST['dbuser']; diff --git a/airtime_mvc/application/controllers/ProvisioningController.php b/airtime_mvc/application/controllers/ProvisioningController.php index fc0c28cbb..bc813ab0d 100644 --- a/airtime_mvc/application/controllers/ProvisioningController.php +++ b/airtime_mvc/application/controllers/ProvisioningController.php @@ -18,6 +18,40 @@ class ProvisioningController extends Zend_Controller_Action * */ + /** + * Endpoint to change Airtime preferences remotely. + * Mainly for use with the dashboard right now. + */ + public function changeAction() { + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + if (!RestAuth::verifyAuth(true, true, $this)) { + return; + } + + try { + // This is hacky and should be genericized + if ($_POST['station_name']) { + Application_Model_Preference::SetStationName($_POST['station_name']); + } + if ($_POST['station_name']) { + Application_Model_Preference::SetStationDescription($_POST['station_name']); + } + } catch (Exception $e) { + $this->getResponse() + ->setHttpResponseCode(400) + ->appendBody("ERROR: " . $e->getMessage()); + Logging::error($e->getMessage()); + echo $e->getMessage() . PHP_EOL; + return; + } + + $this->getResponse() + ->setHttpResponseCode(200) + ->appendBody("OK"); + } + /** * Delete the Airtime Pro station's files from Amazon S3 */