Moved provisioning change function into controller from helper

This commit is contained in:
Duncan Sommerville 2015-03-19 17:32:02 -04:00
parent bd72252e9e
commit 2ec2403cce
2 changed files with 35 additions and 26 deletions

View File

@ -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'];

View File

@ -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
*/