diff --git a/.env b/.env index 4f70e3d709b67de83b9b0e8839b00c9e34ba876c..60d18f216c2b0b39f67a6ae4f621c753e0030348 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres POSTGRES_DB=labpro -POSTGRES_HOST=db \ No newline at end of file +POSTGRES_HOST=db +SOAP_URL=http://host.docker.internal:8080/premium \ No newline at end of file diff --git a/api/subscribe/subscribe.php b/api/subscribe/subscribe.php index 8c5240eb42822d242791ac444a35d7a2098c2e7d..77e7b79144700d6a84144345c9ba4bcce9ae7500 100644 --- a/api/subscribe/subscribe.php +++ b/api/subscribe/subscribe.php @@ -1,4 +1,5 @@ <?php + require_once("../../config/config.php"); if(session_status() === PHP_SESSION_NONE){ session_start(); } @@ -11,30 +12,30 @@ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://service.LMS.com/"> <soap:Body> - <tns:subscribe> + <tns:upgrade> <user_id>' . $user_id . '</user_id> - </tns:subscribe> + </tns:upgrade> </soap:Body> </soap:Envelope>'; $headers = array( "Content-Type: text/xml;charset=\"utf-8\"", ); - $url = "http://host.docker.internal:8080/subscription"; + $url = $_ENV["SOAP_URL"]; $ch = curl_init(); - var_dump($ch); - // var_dump(curl_error($ch)); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($ch); if($response === FALSE){ $_SESSION["error"] = "Subscription request has failed!"; }else{ - $_SESSION["success"] = "Request has been submitted!"; + if($response == "Request failed"){ + $_SESSION["error"] = "Subscritpion request has failed!"; + }else{ + $_SESSION["success"] = $response; + } } header("Location: /profile"); - ?> \ No newline at end of file diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.php index f8cdb97cea44ce0095bb3ec794ab00e871504e8a..3691e6d11c740ea5585e0cc8a939f2b8b1df6091 100644 --- a/app/controllers/ProfileController.php +++ b/app/controllers/ProfileController.php @@ -3,7 +3,33 @@ public function index(){ $middleware = $this->middleware('LoginMiddleware'); $middleware->hasLoggedIn(); - return $this->view('profile','index',[]); + $user_id = $_SESSION["user_id"]; + $request_param = '<?xml version="1.0" encoding="utf-8" ?> + <soap:Envelope + xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:tns="http://service.LMS.com/"> + <soap:Body> + <tns:getPremiumStatus> + <user_id>' . $user_id . '</user_id> + </tns:getPremiumStatus> + </soap:Body> + </soap:Envelope>'; + $headers = array( + "Content-Type: text/xml;charset=\"utf-8\"", + ); + $url = $_ENV["SOAP_URL"]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($ch); + // if($response === FALSE){ + // var_dump("Gagal request"); + // } + // var_dump($response); + return $this->view('profile','index',["premium_status" => $response]); } } ?> \ No newline at end of file diff --git a/app/views/profile/index.php b/app/views/profile/index.php index 5321d46ef6e609c0550b84f54b56f3816d189d20..0d0a121d25ce328c5bac34cf53c77a2e9dd02f5e 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -103,7 +103,10 @@ /> </div> <p id='username-alert'></p> - + <div class='profile-box' id='username-box'> + <p>Premium status :<span class="premium-status"> <?php echo $data['premium_status'] ?></span> </p> + + </div> <div class='profile-toggle-change'> <div class='profile-box' id='password-box'> <p>Password :</p> @@ -129,7 +132,9 @@ <button type='button' onclick='toggle()' class='edit-button' id='profile-button'>Edit</button> </div> <div> - <button id="subscribe-button" type="button" class="edit-button" ><a href="/api/subscribe/subscribe.php">Subscribe</a></button> + <?php if ($data["premium_status"] === 'REJECTED' || $data["premium_status"] === "NOT PREMIUM"){ ?> + <button id="subscribe-button" type="button" class="edit-button" ><a href="/api/subscribe/subscribe.php">Subscribe</a></button> + <?php } ?> </div> </form> </div> diff --git a/docker-compose.yml b/docker-compose.yml index b136ce02b44e30cec6ea6b2add828b8eebe95f6d..fa2a7365c9cce24fd5445e8e314571bfe87063c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: context: . dockerfile: Dockerfile restart: unless-stopped + networks: + - php-network db: image: postgres:latest container_name: db @@ -25,5 +27,9 @@ services: POSTGRES_DB: ${POSTGRES_DB} volumes: - ./mysql:/var/lib/mysql + networks: + - php-network volumes: - mysql: \ No newline at end of file + mysql: +networks: + php-network: \ No newline at end of file diff --git a/public/css/profile/profile.css b/public/css/profile/profile.css index 4e36c9d5b4b8df4ac8b5180af633387f27fb876b..1142b01fb0611735959a1436463f5c6f715ea494 100644 --- a/public/css/profile/profile.css +++ b/public/css/profile/profile.css @@ -152,6 +152,12 @@ a { color: var(--first-color-light); } +.premium-status{ + font-weight: 700; + color: var(--first-color-dark); + font-size: var(--normal-font-size); +} + .change-buttons { display: flex; margin: 3px; diff --git a/public/js/subscribe.js b/public/js/subscribe.js deleted file mode 100644 index c7b02fbcc4942ea1849852f800e0d0a4b08ebb00..0000000000000000000000000000000000000000 --- a/public/js/subscribe.js +++ /dev/null @@ -1,29 +0,0 @@ -const SOAP_URL = "http://localhost:8080/subscription"; - -const subscribe = async () => { - let user_id = 2; - const syntax = ` - <?xml vresion="1.0" encoding="utf-8" ?> - <soapenv:Envelope - xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" - xmlns:tns="http://service.LMS.com/"> - <soapenv:Body> - <tns:subscribe> - <user_id>${user_id}</user_id> - </tns:subscribe> - </soapenv:Body> -</soapenv:Envelope>` - - const xhr = new XMLHttpRequest(); - xhr.open("POST",SOAP_URL, true); - xhr.setRequestHeader("Content-Type","text/xml"); - xhr.onload = function(){ - console.log(this) - if(this.status === 200){ - console.log(this.responseText) - }else{ - console.log(this); - } - } - xhr.send(syntax) -};