1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- class AddProjectAction implements IAction {
- public function execute() {
- if(!Authorize::isLoggedIn() || !Authorize::hasPermission()) {
- return array("error" => "Access not authorized");
- }
- $bucket = $_POST['bucket'] ?? $_GET['bucket'] ?? "";
- $project = $_POST['project'] ?? $_GET['project'] ?? "";
- $region = $_POST['region'] ?? $_GET['region'] ?? "us-east-1";
- $displayName = $_POST['display_name'] ?? $_GET['display_name'] ?? "";
-
- //TODO: scrub inputs
- if(empty($bucket) || empty($displayName) || empty($project)) {
- return array("error" => "One or more required fields missing: bucket, project, display_name");
- }
-
- //TODO: instead of bucket, need to pick CDN url
- //https://d2we20985k2v2g.cloudfront.net/test/hand.png
- $sql = "INSERT INTO projects (bucket, folder, display_name)
- VALUES
- (:bucket, :folder, :display_name);";
- $db = SqliteDatabase::getSingleton();
- $preparedQuery = $db->prepare($sql);
- $preparedQuery->bindValue(':bucket', $bucket);
- $preparedQuery->bindValue(':folder', $project);
- $preparedQuery->bindValue(':display_name', $displayName);
- //$preparedQuery->bindValue(':region', $region);
- try {
- $result = $preparedQuery->execute();
- $loggerData = array();
- $loggerData['display_name'] = $_SESSION['display_name'];
- $loggerData['user_id'] = $_SESSION['user_id'];
- $loggerData['project_display_name'] = $displayName;
- $loggerData['project_folder'] = $project;
- $loggerData['project_bucket'] = $bucket;
- SecurityLogger::action("create-project", $loggerData, time());
- return array("status" => "success", "message" => "Successfully created project '" . $displayName . "'.");
- }
- catch(Exception $e) {
- return array("error" => "Error when creating project '" . $displayName. "': possibly duplicate?" , "exception" => $e->getMessage());
- }
- }
- }
|