예제 #1
0
 function main()
 {
     if ($_SERVER['REQUEST_METHOD'] !== "POST") {
         return array('status' => "error", 'message' => "Only POST requests accepted");
     }
     // Attempt to get database connection
     try {
         $database = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $response = array('status' => "error", 'message' => "Could not connect to the database");
         if (DEV_MODE) {
             $response['details'] = $e->getMessage();
         }
         return $response;
     }
     // Get instance of AccountSession
     $account_session = new AccountSession();
     $session_op = new AccountSessionOperator($database, $account_session);
     // Attempt to register user
     $status = $session_op->attempt_login($_POST['email'], $_POST['pass']);
     if ($status === AccountSessionOperator::LOGIN_OKAY) {
         $account_id = $account_session->get_account_id();
         return array('status' => "okay", 'redirect' => WEB_PATH . '/user/' . $account_id);
     } else {
         $response = array();
         $response['status'] = "error";
         if ($status == AccountSessionOperator::LOGIN_EMPTY_FIELDS) {
             $response['message'] = "Please fill in all fields";
         } else {
             if ($status == AccountSessionOperator::LOGIN_INVALID_EMAIL) {
                 $response['message'] = "Please enter a valid email address";
             } else {
                 if ($status == AccountSessionOperator::LOGIN_BAD_PASSWORD) {
                     $response['message'] = "Your password was incorrect";
                 } else {
                     if ($status == AccountSessionOperator::LOGIN_ATTEMPTS_EXHAUSTED) {
                         $response['message'] = "You have tried to login too many times. Please wait up to 15 minutes.";
                     } else {
                         if ($status == AccountSessionOperator::LOGIN_NOT_FOUND) {
                             $response['message'] = "An account with that email wasn't found, but you can create it!";
                         } else {
                             $response['message'] = "An error occured on our end D: we'll get it fixed; in the meantime, try something else!";
                             if (DEV_MODE) {
                                 $response['details'] = $session_op->get_last_exception_message();
                             }
                             if (DEV_MODE) {
                                 $response['status_code'] = $status;
                             }
                         }
                     }
                 }
             }
         }
         return $response;
     }
 }
예제 #2
0
 function generate_page()
 {
     $account_session = new AccountSession(null);
     $user_template = $this->get_page_template();
     $user_template->set_template_file(SITE_PATH . "/templates/user.template.php");
     try {
         $database_connection = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $this->error_response("The following internal error occured: " . $e->getMessage());
         return SitePage::PAGE_OKAY;
     }
     // Get PageID from page request
     $pageID = $this->request->get_parameter(0);
     $pageID = intval($pageID);
     // Instantiate needed data managers
     $users_database = new UsersDatabase($database_connection);
     $groups_database = new GroupsDatabase($database_connection);
     if ($_SERVER["REQUEST_METHOD"] === "POST") {
         $this->do_post($users_database, $pageID);
     }
     // Get the page user
     $page_user = $users_database->get_user_by_id($pageID);
     // Check for case that user doesn't exist
     if ($page_user === false) {
         $this->error_response("The user you're looking for does not exist :/");
         return SitePage::PAGE_OKAY;
     }
     // Set values of user template
     $user_template->page_id = $pageID;
     $user_template->user_name = $page_user->get_username();
     $user_template->facebook = $page_user->get_facebook();
     $user_template->twitter = $page_user->get_twitter();
     $user_template->linkedin = $page_user->get_linkedin();
     $user_template->email = $page_user->get_email();
     $user_template->bio = $page_user->get_bio();
     // Attempt to add groups to template
     try {
         $user_template->groups = $groups_database->get_groups_by_owner($pageID);
     } catch (PDOException $e) {
         $user_template->groups_fetch_error = $e->getMessage();
     }
     if ($account_session->check_login()) {
         $user_template->login = true;
         // compare loged in userID to userID of page
         if ($account_session->get_account_id() == $pageID) {
             $user_template->is_own_page = true;
         } else {
             $user_template->is_own_page = false;
         }
     }
     return SitePage::PAGE_OKAY;
 }
예제 #3
0
 function generate_page()
 {
     // Get PageID from page request
     $pageID = $this->request->get_parameter(0);
     $pageID = intval($pageID);
     $group_template = $this->get_page_template();
     $group_template->set_template_file(SITE_PATH . "/templates/group.template.php");
     // Instantiate AccountSession without database
     $account_session = new AccountSession(null);
     // Attempt database connection
     try {
         $database_connection = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $this->error_response("The following internal error occured: " . $e->getMessage);
         return SitePage::PAGE_OKAY;
     }
     // Instantiate needed data managers
     $users_database = new UsersDatabase($database_connection);
     $groups_database = new GroupsDatabase($database_connection);
     $projects_database = new ProjectsDatabase($database_connection);
     // Get the page group
     try {
         $page_group = $groups_database->get_group_by_id($pageID);
         // Check for case that group doesn't exist
         if ($page_group === false) {
             $this->error_response("The group you're looking for does not exist :/");
             return SitePage::PAGE_OKAY;
         }
         // Get a list of group projects
         $group_projects = $projects_database->get_projects_by_group($pageID);
     } catch (PDOException $e) {
         $this->error_response("The following internal error occured: " . $e->getMessage());
         return SitePage::PAGE_OKAY;
     }
     // Set values of group template
     $group_template->group_id = $pageID;
     $group_template->group_name = $page_group->get_name();
     $group_template->group_projects = $group_projects;
     if ($account_session->check_login()) {
         $group_template->login = true;
         // compare loged in userID to userID of page
         if ($account_session->get_account_id() == $page_group->get_owner()) {
             $group_template->is_own_group = true;
         } else {
             $group_template->is_own_group = false;
         }
     }
     return SitePage::PAGE_OKAY;
 }
예제 #4
0
 function main()
 {
     if ($_SERVER['REQUEST_METHOD'] !== "POST") {
         return array('status' => "error", 'message' => "Only POST requests accepted");
     }
     // Attempt to get database connection
     try {
         $database = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
         // Get instance of ProjectsDatabase
         $account_session = new AccountSession($database);
         $files_database = new FilesDatabase($database);
         $projects_database = new ProjectsDatabase($database);
         if ($account_session->check_login()) {
             // Attempt to create project folder
             $status = $files_database->create_new_folder(null, "Root Folder");
             if ($status !== FilesDatabase::NEW_ITEM_OKAY) {
                 $err = $this->send_error("Failed to create a project folder");
                 $err['details'] = $files_database->get_last_exception_message();
             }
             $root_folder_id = $files_database->get_last_inserted();
             // Attempt to add new project
             $status = $projects_database->add_new_project($_POST['group_id'], $root_folder_id, $_POST['name']);
             if ($status === ProjectsDatabase::NEW_PROJECT_OKAY) {
                 return array('status' => "okay");
             } else {
                 $response = array();
                 $response['status'] = "error";
                 if ($status == ProjectsDatabase::NEW_PROJECT_INVALID_NAME) {
                     $response['message'] = "Project names must contain only A-z0-9'. and must be between 2 and 40 characters";
                 } else {
                     $response['message'] = "An error occured on our end D: we'll get it fixed; in the meantime, try something else!";
                     if (DEV_MODE) {
                         $response['details'] = $projects_database->get_last_exception_message();
                     }
                     if (DEV_MODE) {
                         $response['status_code'] = $status;
                     }
                 }
                 return $response;
             }
         }
     } catch (PDOException $e) {
         $response = array('status' => "error", 'message' => "Could not connect to the database");
         if (DEV_MODE) {
             $response['details'] = $e->getMessage();
         }
         return $response;
     }
 }
예제 #5
0
 function main()
 {
     if ($_SERVER['REQUEST_METHOD'] !== "POST") {
         return array('status' => "error", 'message' => "Only POST requests accepted");
     }
     // Attempt to get database connection
     try {
         $database = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $response = array('status' => "error", 'message' => "Could not connect to the database");
         if (DEV_MODE) {
             $response['details'] = $e->getMessage();
         }
         return $response;
     }
     // Get instance of UsersDatabase
     $users_database = new UsersDatabase($database);
     // Attempt to register user
     $status = $users_database->attempt_register($_POST['email'], $_POST['pass'], $_POST['name']);
     if ($status === UsersDatabase::REGISTER_OKAY) {
         return array('status' => "okay");
     } else {
         $response = array();
         $response['status'] = "error";
         if ($status == UsersDatabase::REGISTER_EMPTY_FIELDS) {
             $response['message'] = "Please fill in all fields";
         } else {
             if ($status == UsersDatabase::REGISTER_INVALID_NAME) {
                 $response['message'] = "Display name must contain only A-z0-9'. and must be between 2 and 40 characters";
             } else {
                 if ($status == UsersDatabase::REGISTER_INVALID_EMAIL) {
                     $response['message'] = "Please enter a valid email address";
                 } else {
                     $response['message'] = "An error occured on our end D: we'll get it fixed; in the meantime, try something else!";
                     if (DEV_MODE) {
                         $response['details'] = $users_database->get_last_exception_message();
                     }
                     if (DEV_MODE) {
                         $response['status_code'] = $status;
                     }
                 }
             }
         }
         return $response;
     }
 }
예제 #6
0
 function main()
 {
     if ($_SERVER['REQUEST_METHOD'] !== "POST") {
         return array('status' => "error", 'message' => "Only POST requests accepted");
     }
     // Attempt to get database connection
     try {
         $database = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $response = array('status' => "error", 'message' => "Could not connect to the database");
         if (DEV_MODE) {
             $response['details'] = $e->getMessage();
         }
         return $response;
     }
     // Get instance of UsersDatabase
     $account_session = new AccountSession($database);
     $groups_database = new GroupsDatabase($database);
     if ($account_session->check_login()) {
         // Attempt to register user
         $status = $groups_database->add_new_group($account_session->get_account_id(), $_POST['name']);
         if ($status === GroupsDatabase::NEW_GROUP_OKAY) {
             return array('status' => "okay");
         } else {
             $response = array();
             $response['status'] = "error";
             if ($status == GroupsDatabase::NEW_GROUP_INVALID_NAME) {
                 $response['message'] = "Group names must contain only A-z0-9'. and must be between 2 and 40 characters";
             } else {
                 $response['message'] = "An error occured on our end D: we'll get it fixed; in the meantime, try something else!";
                 if (DEV_MODE) {
                     $response['details'] = $users_database->get_last_exception_message();
                 }
                 if (DEV_MODE) {
                     $response['status_code'] = $status;
                 }
             }
             return $response;
         }
     }
 }
예제 #7
0
 function generate_page()
 {
     // Obtain number at the end of the URL
     $pageID = $this->request->get_parameter(0);
     $pageID = intval($pageID);
     try {
         $database_connection = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini');
     } catch (PDOException $e) {
         $this->error_response("The following internal error occured: " . $e->getMessage);
         return SitePage::PAGE_OKAY;
     }
     // Instantiate class for communicating with files tables
     $files_database = new FilesDatabase($database_connection);
     // Set files database as instance variable
     $this->files_database = $files_database;
     if ($_SERVER['REQUEST_METHOD'] === "POST") {
         $this->do_post();
     }
     // Get folder from database
     $folder = $files_database->get_folder_by_id($pageID);
     // Fetch folders and files in the requested folder
     $folders_list = $files_database->get_folders_by_parent($pageID);
     $files_list = $files_database->get_files_by_folder($pageID);
     $this->generate_test_items($folders_list, $files_list);
     // Setup the folder template
     $folder_template = $this->get_page_template();
     $folder_template->set_template_file(SITE_PATH . "/templates/folder.template.php");
     // Set meta data for folder contents
     $folder_template->folder_name = "Test Folder";
     $folder_template->folder_id = $pageID;
     // Set parent directory if applicable
     $parent = $folder->get_parent_id();
     if ($parent != null) {
         $folder_template->parent_uri = WEB_PATH . '/folder/' . $parent;
     }
     // Add folders and files to folder page
     $folder_template->items = array_merge($folders_list, $files_list);
     return SitePage::PAGE_OKAY;
 }