From 693467925099adafb0f025b67a6608927d914fc9 Mon Sep 17 00:00:00 2001 From: Metarock Date: Fri, 13 Aug 2021 22:28:40 +1200 Subject: [PATCH 01/12] php 7.4 --- application/models/entities/Organisation_Model.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 application/models/entities/Organisation_Model.php diff --git a/application/models/entities/Organisation_Model.php b/application/models/entities/Organisation_Model.php new file mode 100644 index 0000000..e69de29 From fc7aa58bdf17bd7dd0cfb9cba8f83628b8ca4f93 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sun, 12 Sep 2021 23:33:23 +1200 Subject: [PATCH 02/12] initiate ASPA-70 --- application/controllers/EnrollmentForm.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 189b943..02d12b6 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -98,8 +98,10 @@ public function makeStripePayment() // Stopping direct access to this method if (!isset($data['name']) || !isset($data['email'])) { - show_error("Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", - "404"); + show_error( + "Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", + "404" + ); } if (CHECK_MEMBERSHIP_PAYMENT) { @@ -145,9 +147,9 @@ public function makeOfflinePayment() $this->load->model('Email_Model'); log_message('debug', "-- makeOfflinePayment function called"); - $this->load->model("GoogleSheets_Model"); - $this->load->model("Verification_Model"); - $this->load->model('Email_Model'); + // $this->load->model("GoogleSheets_Model"); + // $this->load->model("Verification_Model"); + // $this->load->model('Email_Model'); $data['has_paid'] = false; $data["email"] = $this->input->post("email"); From e1c77fa82499382fbbaa7a84849ad571a6cbb221 Mon Sep 17 00:00:00 2001 From: Metarock Date: Mon, 13 Sep 2021 17:45:58 +1200 Subject: [PATCH 03/12] it a little faster, don't know what i did --- application/models/Verification_Model.php | 18 +- assets/js/enrollmentForm.js | 266 +++++++++++----------- 2 files changed, 142 insertions(+), 142 deletions(-) diff --git a/application/models/Verification_Model.php b/application/models/Verification_Model.php index 65b7bd6..718cd65 100644 --- a/application/models/Verification_Model.php +++ b/application/models/Verification_Model.php @@ -1,12 +1,13 @@ GoogleSheets_Model->getNumberOfRecords(); // An array of array of all existing emails, i.e. [[email1], [email2], [email3]] - $this->addresses = array_column($this->GoogleSheets_Model->getCellContents('B2', 'B' . ($sheetSize+1)), 0); + $this->addresses = array_column($this->GoogleSheets_Model->getCellContents('B2', 'B' . ($sheetSize + 1)), 0); // Return true if email exists in google sheet return in_array($emailAddress, $this->addresses); @@ -57,7 +58,7 @@ public function hasUserPaidMembership($emailAddress) $emailKey = array_search($emailAddress, $this->addresses); // Convert key to google coordinate - $emailIndex = 'B' . ($emailKey+2); + $emailIndex = 'B' . ($emailKey + 2); // Check the cell colour of the email cell $colourIs = $this->GoogleSheets_Model->getCellColour($emailIndex); @@ -89,7 +90,7 @@ public function hasUserPaidEvent($emailAddress, $sheetName) $emailKey = array_search($emailAddress, $this->addresses); // Convert key to google coordinate - $emailIndex = 'B' . ($emailKey+2); + $emailIndex = 'B' . ($emailKey + 2); log_message("debug", "INDEX: " . $emailIndex); @@ -124,12 +125,12 @@ public function getMemberInfo($emailAddress) log_message("error", "The member is was not found on the sheet when recording to sheet"); } - // Given that the email exists in the sheet, find its index + // Given that the email exists in the sheet, find its index $emailKey = array_search($emailAddress, $this->addresses); // Convert key to google coordinate - $nameIndex = 'C' . ($emailKey+2); - $upiIndex = 'H' . ($emailKey+2); + $nameIndex = 'C' . ($emailKey + 2); + $upiIndex = 'H' . ($emailKey + 2); // Get member's full name and UPI – these are by default blank string ('') if they do not exist $memberFullName = $this->GoogleSheets_Model->getCellContents($nameIndex, $nameIndex)[0][0] ?? ''; @@ -157,5 +158,4 @@ public static function isValidEmail($emailAddress) // Returns bool variable for whether the sanitised email is valid return (bool) filter_var($emailAddress, FILTER_VALIDATE_EMAIL); } - } diff --git a/assets/js/enrollmentForm.js b/assets/js/enrollmentForm.js index d70e798..7f925e6 100644 --- a/assets/js/enrollmentForm.js +++ b/assets/js/enrollmentForm.js @@ -100,32 +100,32 @@ proceedPayment.style.display = "none"; * go to the next page of the membership system */ function nextPage() { - switch (findActivePage()) { - case 1: - page1.style.display = "none"; - page2.style.display = "flex"; - page3.style.display = "none"; - page4.style.display = "none"; - break; - case 2: - page2.classList.remove("page2-appear"); - page3.classList.add("page3-appear-only-fade"); - page1.style.display = "none"; - page2.style.display = "none"; - page3.style.display = "flex"; - page4.style.display = "none"; - - setTimeout(() => inputEmail.focus(), 1000); // autofocus to name field - break; - case 3: - page3.classList.remove("page3-appear"); - page4.classList.add("page4-appear-only-fade"); - page1.style.display = "none"; - page2.style.display = "none"; - page3.style.display = "none"; - page4.style.display = "flex"; - break; - } + switch (findActivePage()) { + case 1: + page1.style.display = "none"; + page2.style.display = "flex"; + page3.style.display = "none"; + page4.style.display = "none"; + break; + case 2: + page2.classList.remove("page2-appear"); + page3.classList.add("page3-appear-only-fade"); + page1.style.display = "none"; + page2.style.display = "none"; + page3.style.display = "flex"; + page4.style.display = "none"; + + setTimeout(() => inputEmail.focus(), 1000); // autofocus to name field + break; + case 3: + page3.classList.remove("page3-appear"); + page4.classList.add("page4-appear-only-fade"); + page1.style.display = "none"; + page2.style.display = "none"; + page3.style.display = "none"; + page4.style.display = "flex"; + break; + } } @@ -153,42 +153,42 @@ function previousPage() { // Enter key (keycode 13) triggers the click event of the appropriate buttons to go to next page. window.addEventListener("keydown", function (e) { - if (e.keyCode === 13) { - // Prevent form submission from clicking the enter key - e.preventDefault(); - switch (findActivePage()) { - case 1: - buttonReg.click(); //buttonReg does not need an onclick function declaration because it is handled by Webflow - break; - case 2: - ok2.click(); //ok2 does not need an onclick function declaration because it is handled by Webflow - break; - case 3: - // Checking to see if the ok button is disabled. The enter key will only work if it is not disabled - if ($("#div-ok3").css('pointer-events') != 'none') { - ok3.click(); - } - break; - case 4: - if (isActive(submit)) { - submit.click(); - } else if (isActive(proceedPayment)) { - proceedPayment.click(); - } - break; - } - } + if (e.keyCode === 13) { + // Prevent form submission from clicking the enter key + e.preventDefault(); + switch (findActivePage()) { + case 1: + buttonReg.click(); //buttonReg does not need an onclick function declaration because it is handled by Webflow + break; + case 2: + ok2.click(); //ok2 does not need an onclick function declaration because it is handled by Webflow + break; + case 3: + // Checking to see if the ok button is disabled. The enter key will only work if it is not disabled + if ($("#div-ok3").css('pointer-events') != 'none') { + ok3.click(); + } + break; + case 4: + if (isActive(submit)) { + submit.click(); + } else if (isActive(proceedPayment)) { + proceedPayment.click(); + } + break; + } + } }); -ok2.onclick = function() { +ok2.onclick = function () { nextPage(); }; // back buttons onclick function goes to the previous page -back3.onclick = function() { +back3.onclick = function () { previousPage(); }; -back4.onclick = function() { +back4.onclick = function () { previousPage(); }; @@ -199,78 +199,78 @@ back4.onclick = function() { // name/email page (page 3) OK button onclick name and email validation ok3.onclick = function () { - hideAllWarnings(); - emailAddress = inputEmail.value.trim(); // collect email - - if (emailAddress.length === 0) { - inputEmail.style.border = "1px solid red"; - return; - } - inputEmail.style.border = "1px solid #00A22C"; - - // Disabling the ok button to prevent user from clicking on it multiple times - document.getElementById("ok3").classList.add("btn-disabled"); // stopping the ok button from increasing in size when hovered over - $("#div-ok3").css("opacity", "0.2"); // reducing the opacity - $("#div-ok3").css("pointer-events", "none"); // making the ok div unclickable - - showLoading(); - $.ajax({ - cache: false, - url: base_url + "index.php/EnrollmentForm/validate", - method: "POST", - data: { emailAddress: emailAddress }, - complete: function (data) { - if (data.status === 200) { - showSuccess(); - - const name = data.responseJSON.payload; - - // Inject name from the response into the next page - document.getElementById("name-hello").innerHTML = `Hello ${name || "member"},`; - - setTimeout(() => { - nextPage(); - enableOkButton(); - }, 1000); - return; - } - - // If data was not successful, do the following - switch (data.status) { - // change the error message to be "signed up but unpaid" warning - case 403: - errorMsgArray[0].innerHTML = signedUpUnpaidErr[0]; - errorMsgArray[1].innerHTML = signedUpUnpaidErr[1]; - break; - - // change the error message to be "already paid" warning - case 409: - errorMsgArray[0].innerHTML = alreadyPaidEventErr[0]; - errorMsgArray[1].innerHTML = alreadyPaidEventErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - case 404: - errorMsgArray[0].innerHTML = notSignedUpUnpaidErr[0]; - errorMsgArray[1].innerHTML = notSignedUpUnpaidErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - case 412: - errorMsgArray[0].innerHTML = invalidEmailFormatErr[0]; - errorMsgArray[1].innerHTML = invalidEmailFormatErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - default: - errorMsgArray[0].innerHTML = otherErr[0]; - errorMsgArray[1].innerHTML = otherErr[1]; - } - - showWarning(); - enableOkButton(); - }, - }); + hideAllWarnings(); + emailAddress = inputEmail.value.trim(); // collect email + + if (emailAddress.length === 0) { + inputEmail.style.border = "1px solid red"; + return; + } + inputEmail.style.border = "1px solid #00A22C"; + + // Disabling the ok button to prevent user from clicking on it multiple times + document.getElementById("ok3").classList.add("btn-disabled"); // stopping the ok button from increasing in size when hovered over + $("#div-ok3").css("opacity", "0.2"); // reducing the opacity + $("#div-ok3").css("pointer-events", "none"); // making the ok div unclickable + + showLoading(); + $.ajax({ + cache: false, + url: base_url + "index.php/EnrollmentForm/validate", + method: "POST", + data: { emailAddress: emailAddress }, + complete: function (data) { + if (data.status === 200) { + showSuccess(); + + const name = data.responseJSON.payload; + + // Inject name from the response into the next page + document.getElementById("name-hello").innerHTML = `Hello ${name || "member"},`; + + setTimeout(() => { + nextPage(); + enableOkButton(); + }, 1000); + return; + } + + // If data was not successful, do the following + switch (data.status) { + // change the error message to be "signed up but unpaid" warning + case 403: + errorMsgArray[0].innerHTML = signedUpUnpaidErr[0]; + errorMsgArray[1].innerHTML = signedUpUnpaidErr[1]; + break; + + // change the error message to be "already paid" warning + case 409: + errorMsgArray[0].innerHTML = alreadyPaidEventErr[0]; + errorMsgArray[1].innerHTML = alreadyPaidEventErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + case 404: + errorMsgArray[0].innerHTML = notSignedUpUnpaidErr[0]; + errorMsgArray[1].innerHTML = notSignedUpUnpaidErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + case 412: + errorMsgArray[0].innerHTML = invalidEmailFormatErr[0]; + errorMsgArray[1].innerHTML = invalidEmailFormatErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + default: + errorMsgArray[0].innerHTML = otherErr[0]; + errorMsgArray[1].innerHTML = otherErr[1]; + } + + showWarning(); + enableOkButton(); + }, + }); }; /** @@ -340,13 +340,13 @@ function showWarning() { const disabledButtons = [payWeChat, payAli, payPoli]; /* - sets up event listener for button click except for the buttons which are disabled - (the buttons to be disabled will not do anything when clicked on) + sets up event listener for button click except for the buttons which are disabled + (the buttons to be disabled will not do anything when clicked on) */ [payCash, payTransfer, payWeChat, payAli, payCard, payPoli].forEach( (item, index) => { if (!disabledButtons.includes(item)) { - item.addEventListener("click", function(e) { + item.addEventListener("click", function (e) { toggleButton(item); showButton(index); }); @@ -355,8 +355,8 @@ const disabledButtons = [payWeChat, payAli, payPoli]; ); /* - make the to-be-disabled-buttons look like they are disabled - (stopping them from increasing in size when hovered over, reducing their opacity, and making them unclickable) + make the to-be-disabled-buttons look like they are disabled + (stopping them from increasing in size when hovered over, reducing their opacity, and making them unclickable) */ disabledButtons.forEach((buttonToDisable) => { @@ -413,7 +413,7 @@ function showButton(index) { } // TODO: these two buttons must connect to the next step of the enrollment form -submit.onclick = function() { +submit.onclick = function () { $("#enrollment-form").attr( "action", @@ -424,7 +424,7 @@ submit.onclick = function() { document.getElementById("enrollment-form").submit(); }; -proceedPayment.onclick = function() { +proceedPayment.onclick = function () { // get the active button var toggled_index; [payCash, payTransfer, payWeChat, payAli, payCard, payPoli].forEach( From a8cbe32602e508e2f8234915e0cdac584651888b Mon Sep 17 00:00:00 2001 From: Metarock Date: Mon, 20 Sep 2021 16:20:18 +1200 Subject: [PATCH 04/12] [ASPA-70]validate speed is at least 3 - 4 seconds --- application/controllers/EnrollmentForm.php | 25 +++++--- application/core/ASPA_Controller.php | 4 +- application/models/Repository_Model.php | 71 ++++++++++++---------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 887046d..b8b7438 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -27,9 +27,10 @@ function __construct() log_message('debug', "-- from IP address: " . $this->input->ip_address()); } - public function test() { - $this->load->model("Repository_Model"); - $this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID); + public function test() + { + $this->load->model("Repository_Model"); + $this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID); // $event = new Event( // "id3", // "name", @@ -55,7 +56,7 @@ public function test() { // ); print_r("This is a test function."/*$this->Repository_Model->getOrganisation("1")*/); - } + } /** * The "home" page. @@ -85,6 +86,8 @@ public function validate() $this->load->model('Verification_Model'); + $members = $this->Repository_Model->getMemberByEmail($emailAddress); + // If the email is of invalid format, return 412 error if (!isset($emailAddress) || !$this->Verification_Model->isValidEmail($emailAddress)) { $this->createResponse(412, 'Error: Format of email is invalid'); @@ -92,13 +95,13 @@ public function validate() } // If the email does not exist or is not on the membership spreadsheet, return 404 error - if (!$this->Verification_Model->isEmailOnSheet($emailAddress, MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME)) { + if (is_null($members)) { $this->createResponse(404, 'Error: Email incorrect or not found on sheet'); return; } // If the user has already paid for the event, return 409 error - if ($this->Verification_Model->hasUserPaidEvent($emailAddress, $this->eventData['gsheet_name'])) { + if (!$members->feePaid) { $this->createResponse(409, 'Error: already paid for event'); return; } @@ -109,7 +112,8 @@ public function validate() return; } - [$fullName, $UPI] = $this->Verification_Model->getMemberInfo($emailAddress); + // [$fullName, $UPI] = $this->Verification_Model->getMemberInfo($emailAddress); + $fullName = $members->fullName; $this->createResponse(200, "Success", $fullName); } @@ -185,14 +189,17 @@ public function makeOfflinePayment() $data['has_paid'] = false; $data["email"] = $this->input->post("email"); $data['paymentMethod'] = $this->input->post("paymentMethod"); - [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); + $member = $this->Repository_Model->getMemberByEmail($data["email"]); + // [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); + $data['name'] = $member->fullName; + $data['upi'] = $member->upi; if (!isset($data['name']) || !isset($data["email"]) || !isset($data['paymentMethod'])) { show_error("Something went wrong. Please contact uoa.wdcc@gmail.com. Error Code: 001", "500"); } // Only record if the email is not found - if (!($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name']))) { + if (!array_key_exists($member->email, $this->Repository_Model->getMembers())) { $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], ucfirst($data['paymentMethod'])); } else { // Email is found, so find the cell then edit the "How would you like your payment" to be of Offline payment diff --git a/application/core/ASPA_Controller.php b/application/core/ASPA_Controller.php index d791d78..c3ee8ba 100644 --- a/application/core/ASPA_Controller.php +++ b/application/core/ASPA_Controller.php @@ -23,7 +23,7 @@ function __construct() parent::__construct(); $this->load->model("Repository_Model"); $this->load->model("GoogleSheets_Model"); - + $this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID); $this->eventData = $this->loadEventData(); $this->orgData = $this->Repository_Model->getOrganisation("")->toArray(); } @@ -82,6 +82,4 @@ private function loadEventData(): array } return $eventTemp; } - } - diff --git a/application/models/Repository_Model.php b/application/models/Repository_Model.php index f393ac7..ac87b1b 100644 --- a/application/models/Repository_Model.php +++ b/application/models/Repository_Model.php @@ -1,6 +1,6 @@ members[$email] = new Member($email, $fullName, $upi, $signUpDate, $hasPaid); } - + // $member = $this->getMemberByEmail('rick@gmail.com'); + // print_r($this->members['rick@gmail.com']); $this->GoogleSheets_Model->setSpreadsheetId($registrationSheetId); } @@ -89,21 +90,25 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe * @param string the email of the member * @return Member the member object */ - public function getMemberByEmail(string $memberEmail) { - return $this->members[$memberEmail]; + public function getMemberByEmail(string $memberEmail) + { + // return $this->members[$memberEmail]; + return array_key_exists($memberEmail, $this->members) ? $this->members[$memberEmail] : null; } /** * @return Member[] a list of all members */ - public function getMembers() { + public function getMembers() + { return $this->members; } /** * @return Event the event object that corrosponds to the event ID */ - public function getEventById(string $eventId) { + public function getEventById(string $eventId) + { return $this->events[$eventId]; } @@ -111,29 +116,30 @@ public function getEventById(string $eventId) { * Gets an organization */ // TODO: Replace this to return the actual organisation. - public function getOrganisation(string $orgId) { - return new Organisation( - "ASPA", - "01-0129-0469512-00", - $orgId, - "-", - "-", - "Auckland Students Pool Association", - "uoapool@gmail.com", - ); + public function getOrganisation(string $orgId) + { + return new Organisation( + "ASPA", + "01-0129-0469512-00", + $orgId, + "-", + "-", + "Auckland Students Pool Association", + "uoapool@gmail.com", + ); } /** * Get a member's record from an event using their email and the event id * @return Record the member's record, or NULL */ - public function getRecord(string $memberEmail, string $eventId) { + public function getRecord(string $memberEmail, string $eventId) + { $records = $this->getRecordsByEvent($eventId); if (array_key_exists($memberEmail, $records)) { return $records[$memberEmail]; - } - else { + } else { return NULL; } } @@ -142,18 +148,19 @@ public function getRecord(string $memberEmail, string $eventId) { * Get all the records for an event * @return Record[] a list of all records for an event */ - public function getRecordsByEvent(string $eventId) { - $this->GoogleSheets_Model->setCurrentSheetName($eventId); + public function getRecordsByEvent(string $eventId) + { + $this->GoogleSheets_Model->setCurrentSheetName($eventId); - $records = $this->GoogleSheets_Model->getNumberOfRecords(); + $records = $this->GoogleSheets_Model->getNumberOfRecords(); - $array2d = $this->GoogleSheets_Model->getCellContents("A2","K" . ($records + 2)); + $array2d = $this->GoogleSheets_Model->getCellContents("A2", "K" . ($records + 2)); - $allRecords = []; + $allRecords = []; - for ($i = 0; $i < $records; $i++) { - $allRecords[$array2d[$i][1]] = new Record($array2d[$i][1], $eventId, $array2d[$i][0], $array2d[$i][2], $array2d[$i][4], $array2d[$i][5], $array2d[$i][10], $array2d[$i][9], isset($array2d[$i][6])); - } + for ($i = 0; $i < $records; $i++) { + $allRecords[$array2d[$i][1]] = new Record($array2d[$i][1], $eventId, $array2d[$i][0], $array2d[$i][2], $array2d[$i][4], $array2d[$i][5], $array2d[$i][10], $array2d[$i][9], isset($array2d[$i][6])); + } return $allRecords; } @@ -162,7 +169,8 @@ public function getRecordsByEvent(string $eventId) { * Save an event to the database. * @param event the event to save to the database. */ - public function saveEvent(Event $event): Event { + public function saveEvent(Event $event): Event + { $this->GoogleSheets_Model->saveEvent($event->id, EVENT_SHEET_ID_COLUMN, $event->toArray()); return $event; @@ -172,9 +180,10 @@ public function saveEvent(Event $event): Event { * Save a record to the database. * @param record the record to save to the database. */ - public function saveRecord(Record $record) { - $this->GoogleSheets_Model->saveRecord($record->eventID, $record->email, REGISTRATIONS_SHEET_ID_COLUMN, $record->toArray()); + public function saveRecord(Record $record) + { + $this->GoogleSheets_Model->saveRecord($record->eventID, $record->email, REGISTRATIONS_SHEET_ID_COLUMN, $record->toArray()); - return $record; + return $record; } } From ddf5bd05708c6051b5fe27f3d2880f1416effed3 Mon Sep 17 00:00:00 2001 From: Metarock Date: Mon, 27 Sep 2021 18:09:27 +1300 Subject: [PATCH 05/12] web speed between 3 - 4 seconds --- application/controllers/EnrollmentForm.php | 27 +++++++++++----------- application/models/entities/Member.php | 3 +-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index b8b7438..8fbf1ff 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -86,7 +86,7 @@ public function validate() $this->load->model('Verification_Model'); - $members = $this->Repository_Model->getMemberByEmail($emailAddress); + $member = $this->Repository_Model->getMemberByEmail($emailAddress); // If the email is of invalid format, return 412 error if (!isset($emailAddress) || !$this->Verification_Model->isValidEmail($emailAddress)) { @@ -95,25 +95,25 @@ public function validate() } // If the email does not exist or is not on the membership spreadsheet, return 404 error - if (is_null($members)) { + if ($member === null) { $this->createResponse(404, 'Error: Email incorrect or not found on sheet'); return; } // If the user has already paid for the event, return 409 error - if (!$members->feePaid) { + if ($this->Verification_Model->hasUserPaidEvent($emailAddress, $this->eventData['gsheet_name'])) { $this->createResponse(409, 'Error: already paid for event'); return; } // If membership payment status is checked, and user's membership fee has not been paid, return 403 error - if (CHECK_MEMBERSHIP_PAYMENT && !$this->Verification_Model->hasUserPaidMembership($emailAddress)) { + if (CHECK_MEMBERSHIP_PAYMENT && !$member->feePaid) { $this->createResponse(403, "Error: signed up but not paid"); return; } // [$fullName, $UPI] = $this->Verification_Model->getMemberInfo($emailAddress); - $fullName = $members->fullName; + $fullName = $member->fullName; $this->createResponse(200, "Success", $fullName); } @@ -129,7 +129,10 @@ public function makeStripePayment() // Receive data from form, method=POST $data['email'] = $this->input->post('email'); - [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); + $member = $this->Repository_Model->getMemberByEmail($data["email"]); + // [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); + $data['name'] = $member->fullName; + $data['upi'] = $member->upi; // Stopping direct access to this method if (!isset($data['name']) || !isset($data['email'])) { @@ -140,14 +143,15 @@ public function makeStripePayment() } if (CHECK_MEMBERSHIP_PAYMENT) { - $paid_member = ($this->Verification_Model->hasUserPaidMembership($data['email'])); - if (!$paid_member) { + // $paid_member = ($this->Verification_Model->hasUserPaidMembership($data['email'])); + if (!$member->feePaid) { show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500"); } } // Only record if the email is not found - if (!($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name']))) { + // !($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name'])) + if (!array_key_exists($member->email, $this->Repository_Model->getMembers())) { $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], 'Stripe'); } else { // Email is found, so find the cell @@ -178,14 +182,9 @@ public function makeStripePayment() public function makeOfflinePayment() { $this->load->model("GoogleSheets_Model"); - $this->load->model("Verification_Model"); $this->load->model('Email_Model'); log_message('debug', "-- makeOfflinePayment function called"); - // $this->load->model("GoogleSheets_Model"); - // $this->load->model("Verification_Model"); - // $this->load->model('Email_Model'); - $data['has_paid'] = false; $data["email"] = $this->input->post("email"); $data['paymentMethod'] = $this->input->post("paymentMethod"); diff --git a/application/models/entities/Member.php b/application/models/entities/Member.php index 68fb212..188e6dc 100644 --- a/application/models/entities/Member.php +++ b/application/models/entities/Member.php @@ -9,7 +9,7 @@ class Member public string $fullName; public string $upi; public int $signUpDate; // PHP int holds 32 bits. Current epoch time is just under 32 bits I believe - public bool $feePaid; + public bool $feePaid; //membership fee not event fee public function __construct(string $email, string $fullName, string $upi, int $signUpDate, bool $feePaid) { @@ -19,5 +19,4 @@ public function __construct(string $email, string $fullName, string $upi, int $s $this->signUpDate = $signUpDate; $this->feePaid = $feePaid; } - } From 9992f51db69c840a8c8e295ea4237b98fc57e2fb Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 15:10:00 +1300 Subject: [PATCH 06/12] ASPA-70 speed improvement almost done --- application/core/ASPA_Controller.php | 3 ++- application/models/Repository_Model.php | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/application/core/ASPA_Controller.php b/application/core/ASPA_Controller.php index c3ee8ba..a18a925 100644 --- a/application/core/ASPA_Controller.php +++ b/application/core/ASPA_Controller.php @@ -62,8 +62,9 @@ private function loadEventData(): array // Get event details from spreadsheet from range A2 to size of spreadsheet $this->GoogleSheets_Model->setCurrentSheetName("CurrentEventDetails"); - $data = $this->GoogleSheets_Model->getCellContents('A2', 'C' . ($this->GoogleSheets_Model->getNumberOfRecords() + 2)); + $data = $this->GoogleSheets_Model->getCellContents('A2', 'C'); + log_message('debug', "size of main event records " . sizeof($data)); // Important variables we care about $elements = ['time', 'date', 'location', 'title', 'tagline', 'price', 'acc_num', 'desc', 'gsheet_name', 'form_enabled']; diff --git a/application/models/Repository_Model.php b/application/models/Repository_Model.php index ac87b1b..b574737 100644 --- a/application/models/Repository_Model.php +++ b/application/models/Repository_Model.php @@ -30,10 +30,11 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe // Get all the events $this->GoogleSheets_Model->setCurrentSheetName("Events"); - $records = $this->GoogleSheets_Model->getNumberOfRecords(); - $array2d = $this->GoogleSheets_Model->getCellContents("A2", "J" . ($records + 2)); - for ($i = 0; $i < $records; $i++) { + $array2d = $this->GoogleSheets_Model->getCellContents("A2", "J"); + + log_message('debug', "size of event1 records " . sizeof($array2d)); + for ($i = 0; $i < sizeof($array2d); $i++) { $current = $array2d[$i]; $id = $current[0]; $name = $current[1]; @@ -65,11 +66,10 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe $this->GoogleSheets_Model->setCurrentSheetName($membershipSheetName); - $records = $this->GoogleSheets_Model->getNumberOfRecords(); + $array2d = $this->GoogleSheets_Model->getCellContents("A2", "I"); - $array2d = $this->GoogleSheets_Model->getCellContents("A2", "I" . ($records + 2)); - - for ($i = 0; $i < $records; $i++) { + log_message('debug', "size of members1 records " . sizeof($array2d)); + for ($i = 0; $i < sizeof($array2d); $i++) { $current = $array2d[$i]; $signUpDate = intval($current[0]); @@ -80,8 +80,7 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe $this->members[$email] = new Member($email, $fullName, $upi, $signUpDate, $hasPaid); } - // $member = $this->getMemberByEmail('rick@gmail.com'); - // print_r($this->members['rick@gmail.com']); + $this->GoogleSheets_Model->setSpreadsheetId($registrationSheetId); } @@ -92,7 +91,6 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe */ public function getMemberByEmail(string $memberEmail) { - // return $this->members[$memberEmail]; return array_key_exists($memberEmail, $this->members) ? $this->members[$memberEmail] : null; } From 7a1b5f7b7e5ff9648f1f93cea3197bba5e742847 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 15:43:48 +1300 Subject: [PATCH 07/12] ASPA-70 changes to stripe payment function --- application/controllers/EnrollmentForm.php | 43 +++++++++------------- application/models/Repository_Model.php | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 8fbf1ff..40cfca0 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -112,10 +112,7 @@ public function validate() return; } - // [$fullName, $UPI] = $this->Verification_Model->getMemberInfo($emailAddress); - $fullName = $member->fullName; - - $this->createResponse(200, "Success", $fullName); + $this->createResponse(200, "Success", $member->fullName); } /** @@ -128,36 +125,27 @@ public function makeStripePayment() $this->load->model('Verification_Model'); // Receive data from form, method=POST - $data['email'] = $this->input->post('email'); - $member = $this->Repository_Model->getMemberByEmail($data["email"]); - // [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); - $data['name'] = $member->fullName; - $data['upi'] = $member->upi; + $memberEmail = $this->input->post('email'); + $member = $this->Repository_Model->getMemberByEmail($memberEmail); // Stopping direct access to this method - if (!isset($data['name']) || !isset($data['email'])) { - show_error( - "Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", - "404" - ); + if (!isset($member->fullName) || !isset($member->email)) { + show_error("Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", "404"); } - if (CHECK_MEMBERSHIP_PAYMENT) { - // $paid_member = ($this->Verification_Model->hasUserPaidMembership($data['email'])); - if (!$member->feePaid) { - show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500"); - } + if (CHECK_MEMBERSHIP_PAYMENT && !$member->feePaid) { + show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500"); } // Only record if the email is not found - // !($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name'])) - if (!array_key_exists($member->email, $this->Repository_Model->getMembers())) { - $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], 'Stripe'); + //TODO: WE NEED TO PASS THE PROPER EVENT + if (!array_key_exists($member->email, $this->Repository_Model->getRecordsByEvent(''))) { + $this->GoogleSheets_Model->addNewRecord($member->email, $member->fullName, $member->upi, 'Stripe'); } else { // Email is found, so find the cell // Then edit the "How would you like your payment" to be of Stripe payment // Get the row of the specific email from google sheets - $cell = $this->GoogleSheets_Model->getCellCoordinate($data['email'], 'B'); + $cell = $this->GoogleSheets_Model->getCellCoordinate($member->email, 'B'); if (!isset($cell)) { show_error("Something went wrong, your email was not found in the ASPA member list.Error Code: 002", "500"); } @@ -170,10 +158,15 @@ public function makeStripePayment() // Generate the stripe session ID $this->load->model('Stripe_Model'); - $data['session_id'] = $this->Stripe_Model->generateNewSessionId($data['email'], $this->eventData); + $stripeSessionId = $this->Stripe_Model->generateNewSessionId($member->email, $this->eventData); // Initiate the stripe payment - $this->load->view('stripe.php', $data); + $this->load->view('stripe.php', [ + 'email' => $member->email, + 'name' => $member->fullName, + 'upi' => $member->upi, + 'session_id' => $stripeSessionId + ]); } /** diff --git a/application/models/Repository_Model.php b/application/models/Repository_Model.php index b574737..cb2f9f0 100644 --- a/application/models/Repository_Model.php +++ b/application/models/Repository_Model.php @@ -144,7 +144,7 @@ public function getRecord(string $memberEmail, string $eventId) /** * Get all the records for an event - * @return Record[] a list of all records for an event + * @return Record[] returns an map of Records where the member's email is the key. */ public function getRecordsByEvent(string $eventId) { From d612b125d33a66c3d36f52d2774867edf466cac3 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 15:58:02 +1300 Subject: [PATCH 08/12] ASPA-70 minor changes --- application/controllers/EnrollmentForm.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 40cfca0..5658b09 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -138,7 +138,7 @@ public function makeStripePayment() } // Only record if the email is not found - //TODO: WE NEED TO PASS THE PROPER EVENT + //TODO: WE NEED TO PASS THE PROPER EVENT ID if (!array_key_exists($member->email, $this->Repository_Model->getRecordsByEvent(''))) { $this->GoogleSheets_Model->addNewRecord($member->email, $member->fullName, $member->upi, 'Stripe'); } else { @@ -191,7 +191,8 @@ public function makeOfflinePayment() } // Only record if the email is not found - if (!array_key_exists($member->email, $this->Repository_Model->getMembers())) { + //TODO: WE NEED TO PASS THE PROPER EVENT ID + if (!array_key_exists($member->email, $this->Repository_Model->getRecordsByEvent(''))) { $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], ucfirst($data['paymentMethod'])); } else { // Email is found, so find the cell then edit the "How would you like your payment" to be of Offline payment From f9076d18f52d1ae057471f21fca59cf446a1b933 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 16:00:03 +1300 Subject: [PATCH 09/12] ASPA-70 minor changes --- application/core/ASPA_Controller.php | 1 - application/models/Repository_Model.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/application/core/ASPA_Controller.php b/application/core/ASPA_Controller.php index a18a925..fc6e03d 100644 --- a/application/core/ASPA_Controller.php +++ b/application/core/ASPA_Controller.php @@ -64,7 +64,6 @@ private function loadEventData(): array $this->GoogleSheets_Model->setCurrentSheetName("CurrentEventDetails"); $data = $this->GoogleSheets_Model->getCellContents('A2', 'C'); - log_message('debug', "size of main event records " . sizeof($data)); // Important variables we care about $elements = ['time', 'date', 'location', 'title', 'tagline', 'price', 'acc_num', 'desc', 'gsheet_name', 'form_enabled']; diff --git a/application/models/Repository_Model.php b/application/models/Repository_Model.php index cb2f9f0..051df1f 100644 --- a/application/models/Repository_Model.php +++ b/application/models/Repository_Model.php @@ -33,7 +33,6 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe $array2d = $this->GoogleSheets_Model->getCellContents("A2", "J"); - log_message('debug', "size of event1 records " . sizeof($array2d)); for ($i = 0; $i < sizeof($array2d); $i++) { $current = $array2d[$i]; $id = $current[0]; @@ -68,7 +67,6 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe $array2d = $this->GoogleSheets_Model->getCellContents("A2", "I"); - log_message('debug', "size of members1 records " . sizeof($array2d)); for ($i = 0; $i < sizeof($array2d); $i++) { $current = $array2d[$i]; From 7b8ce623f52310f1e052f0b6c9bd1b7f8bd3b235 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 16:03:13 +1300 Subject: [PATCH 10/12] ASPA-70 minor changes --- application/controllers/EnrollmentForm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 5658b09..1a8bbf6 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -139,7 +139,7 @@ public function makeStripePayment() // Only record if the email is not found //TODO: WE NEED TO PASS THE PROPER EVENT ID - if (!array_key_exists($member->email, $this->Repository_Model->getRecordsByEvent(''))) { + if ($this->Repository_Model->getRecord($member->email, '') === null) { $this->GoogleSheets_Model->addNewRecord($member->email, $member->fullName, $member->upi, 'Stripe'); } else { // Email is found, so find the cell @@ -192,7 +192,7 @@ public function makeOfflinePayment() // Only record if the email is not found //TODO: WE NEED TO PASS THE PROPER EVENT ID - if (!array_key_exists($member->email, $this->Repository_Model->getRecordsByEvent(''))) { + if ($this->Repository_Model->getRecord($member->email, '') === null) { $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], ucfirst($data['paymentMethod'])); } else { // Email is found, so find the cell then edit the "How would you like your payment" to be of Offline payment From 617c6f05adcba19da3bf0753ba634d2d201be919 Mon Sep 17 00:00:00 2001 From: Metarock Date: Sat, 2 Oct 2021 16:08:09 +1300 Subject: [PATCH 11/12] ASPA-70 minor changes --- application/models/Repository_Model.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/application/models/Repository_Model.php b/application/models/Repository_Model.php index 051df1f..fe19797 100644 --- a/application/models/Repository_Model.php +++ b/application/models/Repository_Model.php @@ -148,13 +148,11 @@ public function getRecordsByEvent(string $eventId) { $this->GoogleSheets_Model->setCurrentSheetName($eventId); - $records = $this->GoogleSheets_Model->getNumberOfRecords(); - - $array2d = $this->GoogleSheets_Model->getCellContents("A2", "K" . ($records + 2)); + $array2d = $this->GoogleSheets_Model->getCellContents("A2", "K"); $allRecords = []; - for ($i = 0; $i < $records; $i++) { + for ($i = 0; $i < sizeof($array2d); $i++) { $allRecords[$array2d[$i][1]] = new Record($array2d[$i][1], $eventId, $array2d[$i][0], $array2d[$i][2], $array2d[$i][4], $array2d[$i][5], $array2d[$i][10], $array2d[$i][9], isset($array2d[$i][6])); } From a311eb639255007cd057317b18a2e759bed2991b Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sat, 2 Oct 2021 16:12:30 +1300 Subject: [PATCH 12/12] ASPA-70 Reset JS file with only whitespace changes --- assets/js/enrollmentForm.js | 266 ++++++++++++++++++------------------ 1 file changed, 133 insertions(+), 133 deletions(-) diff --git a/assets/js/enrollmentForm.js b/assets/js/enrollmentForm.js index 7f925e6..d70e798 100644 --- a/assets/js/enrollmentForm.js +++ b/assets/js/enrollmentForm.js @@ -100,32 +100,32 @@ proceedPayment.style.display = "none"; * go to the next page of the membership system */ function nextPage() { - switch (findActivePage()) { - case 1: - page1.style.display = "none"; - page2.style.display = "flex"; - page3.style.display = "none"; - page4.style.display = "none"; - break; - case 2: - page2.classList.remove("page2-appear"); - page3.classList.add("page3-appear-only-fade"); - page1.style.display = "none"; - page2.style.display = "none"; - page3.style.display = "flex"; - page4.style.display = "none"; - - setTimeout(() => inputEmail.focus(), 1000); // autofocus to name field - break; - case 3: - page3.classList.remove("page3-appear"); - page4.classList.add("page4-appear-only-fade"); - page1.style.display = "none"; - page2.style.display = "none"; - page3.style.display = "none"; - page4.style.display = "flex"; - break; - } + switch (findActivePage()) { + case 1: + page1.style.display = "none"; + page2.style.display = "flex"; + page3.style.display = "none"; + page4.style.display = "none"; + break; + case 2: + page2.classList.remove("page2-appear"); + page3.classList.add("page3-appear-only-fade"); + page1.style.display = "none"; + page2.style.display = "none"; + page3.style.display = "flex"; + page4.style.display = "none"; + + setTimeout(() => inputEmail.focus(), 1000); // autofocus to name field + break; + case 3: + page3.classList.remove("page3-appear"); + page4.classList.add("page4-appear-only-fade"); + page1.style.display = "none"; + page2.style.display = "none"; + page3.style.display = "none"; + page4.style.display = "flex"; + break; + } } @@ -153,42 +153,42 @@ function previousPage() { // Enter key (keycode 13) triggers the click event of the appropriate buttons to go to next page. window.addEventListener("keydown", function (e) { - if (e.keyCode === 13) { - // Prevent form submission from clicking the enter key - e.preventDefault(); - switch (findActivePage()) { - case 1: - buttonReg.click(); //buttonReg does not need an onclick function declaration because it is handled by Webflow - break; - case 2: - ok2.click(); //ok2 does not need an onclick function declaration because it is handled by Webflow - break; - case 3: - // Checking to see if the ok button is disabled. The enter key will only work if it is not disabled - if ($("#div-ok3").css('pointer-events') != 'none') { - ok3.click(); - } - break; - case 4: - if (isActive(submit)) { - submit.click(); - } else if (isActive(proceedPayment)) { - proceedPayment.click(); - } - break; - } - } + if (e.keyCode === 13) { + // Prevent form submission from clicking the enter key + e.preventDefault(); + switch (findActivePage()) { + case 1: + buttonReg.click(); //buttonReg does not need an onclick function declaration because it is handled by Webflow + break; + case 2: + ok2.click(); //ok2 does not need an onclick function declaration because it is handled by Webflow + break; + case 3: + // Checking to see if the ok button is disabled. The enter key will only work if it is not disabled + if ($("#div-ok3").css('pointer-events') != 'none') { + ok3.click(); + } + break; + case 4: + if (isActive(submit)) { + submit.click(); + } else if (isActive(proceedPayment)) { + proceedPayment.click(); + } + break; + } + } }); -ok2.onclick = function () { +ok2.onclick = function() { nextPage(); }; // back buttons onclick function goes to the previous page -back3.onclick = function () { +back3.onclick = function() { previousPage(); }; -back4.onclick = function () { +back4.onclick = function() { previousPage(); }; @@ -199,78 +199,78 @@ back4.onclick = function () { // name/email page (page 3) OK button onclick name and email validation ok3.onclick = function () { - hideAllWarnings(); - emailAddress = inputEmail.value.trim(); // collect email - - if (emailAddress.length === 0) { - inputEmail.style.border = "1px solid red"; - return; - } - inputEmail.style.border = "1px solid #00A22C"; - - // Disabling the ok button to prevent user from clicking on it multiple times - document.getElementById("ok3").classList.add("btn-disabled"); // stopping the ok button from increasing in size when hovered over - $("#div-ok3").css("opacity", "0.2"); // reducing the opacity - $("#div-ok3").css("pointer-events", "none"); // making the ok div unclickable - - showLoading(); - $.ajax({ - cache: false, - url: base_url + "index.php/EnrollmentForm/validate", - method: "POST", - data: { emailAddress: emailAddress }, - complete: function (data) { - if (data.status === 200) { - showSuccess(); - - const name = data.responseJSON.payload; - - // Inject name from the response into the next page - document.getElementById("name-hello").innerHTML = `Hello ${name || "member"},`; - - setTimeout(() => { - nextPage(); - enableOkButton(); - }, 1000); - return; - } - - // If data was not successful, do the following - switch (data.status) { - // change the error message to be "signed up but unpaid" warning - case 403: - errorMsgArray[0].innerHTML = signedUpUnpaidErr[0]; - errorMsgArray[1].innerHTML = signedUpUnpaidErr[1]; - break; - - // change the error message to be "already paid" warning - case 409: - errorMsgArray[0].innerHTML = alreadyPaidEventErr[0]; - errorMsgArray[1].innerHTML = alreadyPaidEventErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - case 404: - errorMsgArray[0].innerHTML = notSignedUpUnpaidErr[0]; - errorMsgArray[1].innerHTML = notSignedUpUnpaidErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - case 412: - errorMsgArray[0].innerHTML = invalidEmailFormatErr[0]; - errorMsgArray[1].innerHTML = invalidEmailFormatErr[1]; - break; - - // change the error message to be "unrecognized email, please sign up" warning - default: - errorMsgArray[0].innerHTML = otherErr[0]; - errorMsgArray[1].innerHTML = otherErr[1]; - } - - showWarning(); - enableOkButton(); - }, - }); + hideAllWarnings(); + emailAddress = inputEmail.value.trim(); // collect email + + if (emailAddress.length === 0) { + inputEmail.style.border = "1px solid red"; + return; + } + inputEmail.style.border = "1px solid #00A22C"; + + // Disabling the ok button to prevent user from clicking on it multiple times + document.getElementById("ok3").classList.add("btn-disabled"); // stopping the ok button from increasing in size when hovered over + $("#div-ok3").css("opacity", "0.2"); // reducing the opacity + $("#div-ok3").css("pointer-events", "none"); // making the ok div unclickable + + showLoading(); + $.ajax({ + cache: false, + url: base_url + "index.php/EnrollmentForm/validate", + method: "POST", + data: { emailAddress: emailAddress }, + complete: function (data) { + if (data.status === 200) { + showSuccess(); + + const name = data.responseJSON.payload; + + // Inject name from the response into the next page + document.getElementById("name-hello").innerHTML = `Hello ${name || "member"},`; + + setTimeout(() => { + nextPage(); + enableOkButton(); + }, 1000); + return; + } + + // If data was not successful, do the following + switch (data.status) { + // change the error message to be "signed up but unpaid" warning + case 403: + errorMsgArray[0].innerHTML = signedUpUnpaidErr[0]; + errorMsgArray[1].innerHTML = signedUpUnpaidErr[1]; + break; + + // change the error message to be "already paid" warning + case 409: + errorMsgArray[0].innerHTML = alreadyPaidEventErr[0]; + errorMsgArray[1].innerHTML = alreadyPaidEventErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + case 404: + errorMsgArray[0].innerHTML = notSignedUpUnpaidErr[0]; + errorMsgArray[1].innerHTML = notSignedUpUnpaidErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + case 412: + errorMsgArray[0].innerHTML = invalidEmailFormatErr[0]; + errorMsgArray[1].innerHTML = invalidEmailFormatErr[1]; + break; + + // change the error message to be "unrecognized email, please sign up" warning + default: + errorMsgArray[0].innerHTML = otherErr[0]; + errorMsgArray[1].innerHTML = otherErr[1]; + } + + showWarning(); + enableOkButton(); + }, + }); }; /** @@ -340,13 +340,13 @@ function showWarning() { const disabledButtons = [payWeChat, payAli, payPoli]; /* - sets up event listener for button click except for the buttons which are disabled - (the buttons to be disabled will not do anything when clicked on) + sets up event listener for button click except for the buttons which are disabled + (the buttons to be disabled will not do anything when clicked on) */ [payCash, payTransfer, payWeChat, payAli, payCard, payPoli].forEach( (item, index) => { if (!disabledButtons.includes(item)) { - item.addEventListener("click", function (e) { + item.addEventListener("click", function(e) { toggleButton(item); showButton(index); }); @@ -355,8 +355,8 @@ const disabledButtons = [payWeChat, payAli, payPoli]; ); /* - make the to-be-disabled-buttons look like they are disabled - (stopping them from increasing in size when hovered over, reducing their opacity, and making them unclickable) + make the to-be-disabled-buttons look like they are disabled + (stopping them from increasing in size when hovered over, reducing their opacity, and making them unclickable) */ disabledButtons.forEach((buttonToDisable) => { @@ -413,7 +413,7 @@ function showButton(index) { } // TODO: these two buttons must connect to the next step of the enrollment form -submit.onclick = function () { +submit.onclick = function() { $("#enrollment-form").attr( "action", @@ -424,7 +424,7 @@ submit.onclick = function () { document.getElementById("enrollment-form").submit(); }; -proceedPayment.onclick = function () { +proceedPayment.onclick = function() { // get the active button var toggled_index; [payCash, payTransfer, payWeChat, payAli, payCard, payPoli].forEach(