From d9be6c8a53b2ca87237243fa97bc8b1a80a8d378 Mon Sep 17 00:00:00 2001
From: mrsyaban <mrsyaban99@gmail.com>
Date: Mon, 13 Nov 2023 13:08:11 +0700
Subject: [PATCH] feat: getprofile

---
 src/app/controllers/app/app_controller.php  | 10 +++---
 src/app/controllers/login/post_login.php    |  2 +-
 src/app/controllers/profile/get_profile.php | 40 +++++++++++++++++++++
 src/app/core/app.php                        |  2 ++
 src/app/init.php                            |  1 +
 5 files changed, 49 insertions(+), 6 deletions(-)
 create mode 100644 src/app/controllers/profile/get_profile.php

diff --git a/src/app/controllers/app/app_controller.php b/src/app/controllers/app/app_controller.php
index 5c8d734..ed70961 100644
--- a/src/app/controllers/app/app_controller.php
+++ b/src/app/controllers/app/app_controller.php
@@ -7,11 +7,11 @@ class AppController
     // Session validation
     session_start();
 
-    if (isset($_SESSION["is_premium"]) && $_SESSION["is_premium"]) {
-      http_response_code(403);
-      header("Location: http://localhost:5173");
-      return;
-    }
+    // if (isset($_SESSION["is_premium"]) && $_SESSION["is_premium"]) {
+    //   http_response_code(403);
+    //   header("Location: http://localhost:5173");
+    //   return;
+    // }
 
     if (!isset($_SESSION["user_id"])) {
       session_destroy();
diff --git a/src/app/controllers/login/post_login.php b/src/app/controllers/login/post_login.php
index 7a54b65..3313dd0 100644
--- a/src/app/controllers/login/post_login.php
+++ b/src/app/controllers/login/post_login.php
@@ -23,7 +23,7 @@ class PostLoginController
                 } else {
                     if (password_verify($password, $user['password'])) {
                         $_SESSION["start"] = time();
-                        $_SESSION["expire"] = time() + 60 * 5;
+                        $_SESSION["expire"] = time() + 60 * 1000;
                         $_SESSION["user_id"] = $user['id_user'];
 
                         if ($username == "premium") {
diff --git a/src/app/controllers/profile/get_profile.php b/src/app/controllers/profile/get_profile.php
new file mode 100644
index 0000000..755ce3d
--- /dev/null
+++ b/src/app/controllers/profile/get_profile.php
@@ -0,0 +1,40 @@
+<?php
+
+class getProfileController
+{
+  public function call()
+  {
+    require_once __DIR__ . "/../../views/login/login.php";
+    session_start();
+    // print_r($_SESSION);
+    // if (isset($_SESSION['user_id'])) {
+      $user_id = "4";
+      // if (isset($_GET["user_id"])) {
+      //   $user_id = $_GET["user_id"];
+      // } 
+
+      $userModel = new UserModel();
+      $profile = $userModel->getUserInfo(4);
+  
+      $data = [
+        "name" => $profile->name,
+        "username" => $profile->username,
+        "url_profpic" => $profile->url_profpic,
+        "is_admin" => $profile->is_admin,
+      ];
+      header("Access-Control-Allow-Origin: http://localhost:3000");
+      header("Access-Control-Allow-Credentials: true");
+      header("Max-Age: 86400");
+      header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+      // header("Access-Control-Allow-Headers: $_SERVER[HTTP_ACCESS_CONTROL_REQUEST_HEADERS]");
+      echo json_encode($data);
+    // } else {
+    //   session_destroy();
+
+    //   http_response_code(403);
+    //   header("Location: " . BASE_URL . "/login");
+
+    //   return;
+    // }
+  }
+}
\ No newline at end of file
diff --git a/src/app/core/app.php b/src/app/core/app.php
index 4da6d4e..2b08fb5 100644
--- a/src/app/core/app.php
+++ b/src/app/core/app.php
@@ -7,6 +7,8 @@ class App
     $url = $this->parseURL();
     $router = new Router();
 
+    $router->get("public/profile", new getProfileController());
+
     $router->get("public", new AppController());
     $router->get("public/home", new AppController());
     $router->get("public/search", new AppController());
diff --git a/src/app/init.php b/src/app/init.php
index 21ccb49..c83fbbb 100644
--- a/src/app/init.php
+++ b/src/app/init.php
@@ -39,6 +39,7 @@ require_once __DIR__ . "/controllers/library/get_library.php";
 require_once __DIR__ . "/controllers/signup/get_signup.php";
 require_once __DIR__ . "/controllers/signup/post_signup.php";
 require_once __DIR__ . "/controllers/search/get_search.php";
+require_once __DIR__ . "/controllers/profile/get_profile.php";
 
 require_once __DIR__ . "/controllers/app/app_controller.php";
 
-- 
GitLab