From 239027e960196ce541342cdae5c6ab644cd3b67b Mon Sep 17 00:00:00 2001 From: henryanandsr <13521004@std.stei.itb.ac.id> Date: Fri, 17 Nov 2023 12:29:23 +0700 Subject: [PATCH] feat : add rest api key --- app/controllers/assignments.php | 1 + app/views/assignments/index.php | 1 + config/.env.example | 3 ++- public/js/assignments.js | 5 ++--- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/assignments.php b/app/controllers/assignments.php index 78c5817..e1e0b26 100644 --- a/app/controllers/assignments.php +++ b/app/controllers/assignments.php @@ -10,6 +10,7 @@ class Assignments extends Controller{ $data['style'] = "/public/css/dashboard.css"; $data['style'] = "/public/css/userlist.css"; $data['user_id'] = $_SESSION['user_id']; + $data['apiKey'] = getenv('REST_KEY'); if (isset($_SESSION['username'])) { $this->view('header/index', $data); $this->view('navbar/index', $data); diff --git a/app/views/assignments/index.php b/app/views/assignments/index.php index 34219a4..42caf2c 100644 --- a/app/views/assignments/index.php +++ b/app/views/assignments/index.php @@ -11,6 +11,7 @@ <script> const sid = <?php echo json_encode($_GET['sid']); ?>; const uid = <?php echo json_encode($data['user_id']); ?>; + const key = <?php echo json_encode($data['apiKey']); ?>; </script> <script src="/public/js/assignments.js"></script> \ No newline at end of file diff --git a/config/.env.example b/config/.env.example index b62c470..fe575e3 100644 --- a/config/.env.example +++ b/config/.env.example @@ -3,4 +3,5 @@ DB_USER=scholee DB_PASSWORD=password DB_NAME=scholee SOAP_KEY=kunciT -WSDL=http://soap-service:8080/ws/ \ No newline at end of file +WSDL=http://soap-service:8080/ws/ +REST_KEY=phpKey \ No newline at end of file diff --git a/public/js/assignments.js b/public/js/assignments.js index c52cec2..8a97b4a 100644 --- a/public/js/assignments.js +++ b/public/js/assignments.js @@ -4,12 +4,11 @@ function renderAssignments(){ */ const element = document.getElementById("content"); - + const xhr = new XMLHttpRequest(); xhr.open("GET", `http://localhost:5001/api/assignment/${sid}`) xhr.setRequestHeader("user_id", uid); - console.log(uid) - console.log("ASSIGNMENT JS") + xhr.setRequestHeader("x-api-key", key) xhr.onload = () => { const res = JSON.parse(xhr.response); -- GitLab