diff --git a/public/js/profile.js b/public/js/profile.js index 632b737498fad28997dce1c54accf822419603ec..b9b5ab0b5c44ab5fa5563d02d19759b061b4f0eb 100644 --- a/public/js/profile.js +++ b/public/js/profile.js @@ -91,7 +91,7 @@ function showExp(){ const parentElement = document.getElementById("levelcirle"); let html = ""; - const level = Math.floor(response/100)+1; + const level = Math.floor(response/100); const exp = response%100; document.querySelector('ul.skills li.sk-cms').style.setProperty('--per', exp); diff --git a/server/controller/auth/DetailFact.php b/server/controller/auth/DetailFact.php index 5f827b341469c7d95e059f5e911697723f5b59c9..648b54be2e67d34e34ed6eecd4f8aab802613fc0 100644 --- a/server/controller/auth/DetailFact.php +++ b/server/controller/auth/DetailFact.php @@ -1,6 +1,9 @@ <?php $API = $_ENV['USER_KEY']; +$userCookie = $_COOKIE['user']; +$userData = json_decode($userCookie); +$idUser = $userData[0]->id; if(isset($_GET['subscribe'])){ $subs = $_GET['subscribe']; @@ -75,6 +78,7 @@ if(isset($_GET['subscribe'])){ if ($data) { + addExp($idUser); echo json_encode($data); } else { echo 'API request failed'; @@ -242,6 +246,46 @@ function unSubscribe(){ curl_close($curl); + if (curl_errno($curl)) { + echo 'cURL Error: ' . curl_error($curl); + } else { + $xml = simplexml_load_string($response); + return $xml->xpath('//return')[0]; + } +} + + +function addExp($id){ + $serviceUrl = $_ENV['SOAP_URL_USER_LEVEL']."?APIkey=".$_ENV["SOAP_KEY"]; + + $soapRequest = ' + <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + <Body> + <addExpUser xmlns="http://Services.nutricraft.org/"> + <arg0 xmlns="">'.$id.'</arg0> + <arg1 xmlns="">10</arg1> + </addExpUser> + </Body> +</Envelope>'; + + $options = [ + CURLOPT_URL => $serviceUrl, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $soapRequest, + CURLOPT_HTTPHEADER => [ + 'Content-Type: text/xml; charset=utf-8', + 'Content-Length: ' . strlen($soapRequest), + ], + ]; + + $curl = curl_init(); + curl_setopt_array($curl, $options); + + $response = curl_exec($curl); + + curl_close($curl); + if (curl_errno($curl)) { echo 'cURL Error: ' . curl_error($curl); } else { diff --git a/server/controller/auth/Fact.php b/server/controller/auth/Fact.php index e7bfccd2a8c8128d43ba4a4aad6cf44a3f87bbd6..789df1831d392e8bce20baf3e697f0b66abdf260 100644 --- a/server/controller/auth/Fact.php +++ b/server/controller/auth/Fact.php @@ -1,44 +1,7 @@ <?php $API = $_ENV['USER_KEY']; -// use data\Content; -// require_once('../../handler/data/Content.php'); -// require_once('../../db/Database.php'); - -// $content = new Content(); - - -// if(isset($_GET['select'])){ -// $select = $_GET['select']; -// $page = $_GET['page']; -// $page = ($page-1)*10; -// if(isset($_GET['search'])){ -// $search = $_GET['search']; -// $result = $content->FindByTitle($search, $select, $page); -// }else{ -// $result = $content->FindAllPaging($select, $page); -// } - -// echo json_encode($result); -// } - -// if(isset($_GET['show'])){ -// $page = $_GET['page']; -// $page = ($page-1)*2; -// $select = $_GET['Select']; -// $result = $content->FindAllPaging($select, $page); -// echo json_encode($result); -// } - -// if(isset($_GET['pageNumber'])){ -// if(isset($_GET['search'])){ -// $search = $_GET['search']; -// $result = $content->FindAllSearch($search); -// }else{ -// $result = $content->FindAll($search); -// } -// echo json_encode($result); - +// u /////////////////////////// if(isset($_GET['select'])){ $select = $_GET['select']; @@ -372,97 +335,3 @@ function getUUID($idSubs) { return $ret; } } - -// if(isset($_GET['search'])){ -// $search = $_GET['search']; -// echo $search; -// $content = curl_init(); -// curl_setopt($content, CURLOPT_URL, "http://nutricraft-express:8080/content/title/$search"); -// curl_setopt($content, CURLOPT_RETURNTRANSFER, 1); - -// $response = curl_exec($content); - -// // if (curl_errno($content)) { -// // echo 'Curl error: ' . curl_error($content); -// // } - -// curl_close($content); - -// echo $response; - -// // $data = json_decode($response, true); - -// // $idPhotoArray = array_map(function($item) { -// // return $item['id_photo']; -// // }, $data['data']); - -// // $path_photo = array(); - -// // for($i = 0; $i < count($idPhotoArray); $i++) { -// // $idPhoto = $idPhotoArray[$i]; -// // $photo = curl_init(); -// // curl_setopt($photo, CURLOPT_URL, "http://nutricraft-express:8080/image/$idPhoto"); -// // curl_setopt($photo, CURLOPT_RETURNTRANSFER, 1); - -// // $tempResponse = curl_exec($photo); - -// // if (curl_errno($photo)) { -// // echo 'Curl error: ' . curl_error($photo); -// // } - -// // curl_close($photo); - -// // $tempResponse = json_decode($tempResponse, true); -// // $url = $tempResponse['data']['url']; - -// // $path_photo[$i] = $url; -// // } - -// // for($i = 0; $i < count($data['data']); $i++) { -// // $data['data'][$i]['path_photo'] = $path_photo[$i]; -// // } - -// // if ($data) { -// // echo json_encode($data); -// // } else { -// // echo 'API request failed'; -// // } -// } -// else{ -// $serviceUrl = $_ENV['SOAP_URL_SUBSCRIBE']."?APIkey=".$_ENV["SOAP_KEY"]; - -// $soapRequest = ' -// <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> -// <Body> -// <getCreators xmlns="http://Services.nutricraft.org/"> -// <arg0 xmlns="">1</arg0> -// </getCreators> -// </Body> -// </Envelope>'; - -// $options = [ -// CURLOPT_URL => $serviceUrl, -// CURLOPT_RETURNTRANSFER => true, -// CURLOPT_POST => true, -// CURLOPT_POSTFIELDS => $soapRequest, -// CURLOPT_HTTPHEADER => [ -// 'Content-Type: text/xml; charset=utf-8', -// 'Content-Length: ' . strlen($soapRequest), -// ], -// ]; - -// $curl = curl_init(); -// curl_setopt_array($curl, $options); - -// $response = curl_exec($curl); - -// curl_close($curl); - -// if (curl_errno($curl)) { -// echo 'cURL Error: ' . curl_error($curl); -// } else { -// $xml = new SimpleXMLElement($response); -// $returnValue = (string)$xml->xpath('//return')[0]; -// echo($returnValue); -// } -// } diff --git a/server/controller/auth/Register.php b/server/controller/auth/Register.php index 587245807385c8e86f0fc25d5ef4af9fdfe6541e..1695fda6c4fa084705eec5f3188d6526ec7e5dcf 100644 --- a/server/controller/auth/Register.php +++ b/server/controller/auth/Register.php @@ -33,6 +33,7 @@ if (isset($_POST['uname']) && isset($_POST['psw']) && isset($_POST['email']) && $phoneNumber = $_POST['phoneNumber']; $user->Insert($username, $email, $phoneNumber, $password, "user"); $id = $user->FindIdByEmail($email); + addCoins($id); if(is_dir("../../../assets/user/$id" == false)){ echo "<script>('create folder')</script>"; mkdir("../../../assets/user/$id",0777,true); @@ -42,4 +43,43 @@ if (isset($_POST['uname']) && isset($_POST['psw']) && isset($_POST['email']) && } +function addCoins($id){ + $serviceUrl = $_ENV['SOAP_URL_USER_LEVEL']."?APIkey=".$_ENV["SOAP_KEY"]; + + $soapRequest = ' + <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + <Body> + <newUser xmlns="http://Services.nutricraft.org/"> + <arg0 xmlns="">'.$id.'</arg0> + </newUser> + </Body> + </Envelope>'; + + $options = [ + CURLOPT_URL => $serviceUrl, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $soapRequest, + CURLOPT_HTTPHEADER => [ + 'Content-Type: text/xml; charset=utf-8', + 'Content-Length: ' . strlen($soapRequest), + ], + ]; + + $curl = curl_init(); + curl_setopt_array($curl, $options); + + $response = curl_exec($curl); + + curl_close($curl); + + if (curl_errno($curl)) { + echo 'cURL Error: ' . curl_error($curl); + } else { + $xml = new SimpleXMLElement($response); + $returnValue = (string)$xml->xpath('//return')[0]; + echo $returnValue; + } +} + ?> \ No newline at end of file