function main($template)
 {
     $account_session = new AccountSession(null);
     $account_session->logout();
     header("Location: " . WEB_PATH);
     return ContentPage::PAGE_REDIRECT;
 }
 public function testEmptyLoginFails()
 {
     // Create an account session
     $as = new AccountSession(null);
     // Login with empty string as username nad password
     $status = $as->attempt_login('', '');
     // Assert that the corresponding status code is given
     $this->assertEquals($status, AccountSession::LOGIN_EMPTY_FIELDS);
 }
 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;
     }
 }
Exemple #4
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;
 }
Exemple #5
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;
 }
 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;
     }
 }
 function main($template)
 {
     // Get instance of AccountSession
     $account_session = new AccountSession(null);
     $contents = new \Framework\Template();
     $contents->set_template_file(SITE_PATH . "/templates/simple_message.template.php");
     $template->set_template_file(SITE_PATH . "/templates/full.template.php");
     $template->contents_template = $contents;
     $contents->title = "Contents Page";
     if ($account_session->check_login()) {
         $contents->message = "Yes, logged in!";
     } else {
         $contents->message = "No, not logged in!";
     }
     return ContentPage::PAGE_OKAY;
 }
 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;
         }
     }
 }