From f9dd96d7c0a38217df44c7287d24f627bb05e3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Wed, 8 Feb 2023 01:51:26 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20du=20gitignore=20+=20G=C3=A9n?= =?UTF-8?q?=C3=A9ricit=C3=A9=20du=20js=20au=20niveaux=20du=20test=20et=20d?= =?UTF-8?q?e=20la=20solution=20des=20=C3=A9nigme=20+=20Gestion=20de=20cons?= =?UTF-8?q?tante=20du=20js=20(push=20pr=C3=A9vu=20pour=20le=20serveur=20de?= =?UTF-8?q?=20test)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- Config/Config.php | 4 +- Model/AdminModel.php | 52 ----------------------- View/src/JS/CesarDecrypt.js | 41 ------------------- View/src/JS/CesarEncrypt.js | 41 ------------------- View/src/JS/Chouette.js | 31 -------------- View/src/JS/ChuckNorris.js | 59 --------------------------- View/src/JS/Const.js | 5 +++ View/src/JS/DoubleElement.js | 34 --------------- View/src/JS/Hanoi.js | 38 ----------------- View/src/JS/Palindrome.js | 34 --------------- View/src/JS/Submit.js | 10 +++++ View/src/JS/TrianglePascal.js | 39 ------------------ View/src/JS/base.js | 7 +++- View/src/JS/baseTest.js | 7 +++- View/src/pages/Enigme/EnigmePage.php | 12 +++++- View/src/pages/Multijoueur/Partie.php | 15 ++++++- 17 files changed, 52 insertions(+), 380 deletions(-) delete mode 100644 View/src/JS/CesarDecrypt.js delete mode 100644 View/src/JS/CesarEncrypt.js delete mode 100644 View/src/JS/Chouette.js delete mode 100644 View/src/JS/ChuckNorris.js create mode 100644 View/src/JS/Const.js delete mode 100644 View/src/JS/DoubleElement.js delete mode 100644 View/src/JS/Hanoi.js delete mode 100644 View/src/JS/Palindrome.js create mode 100644 View/src/JS/Submit.js delete mode 100644 View/src/JS/TrianglePascal.js diff --git a/.gitignore b/.gitignore index a6967c98..f75a5150 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ /.idea -*.db \ No newline at end of file +*.db +/.vscode \ No newline at end of file diff --git a/Config/Config.php b/Config/Config.php index 985f3c33..69f05324 100644 --- a/Config/Config.php +++ b/Config/Config.php @@ -3,8 +3,8 @@ $rep = ''; // BD -$dsn = './scripted.db'; -// $dsn = 'C:\\wamp64\\www\\scripted.db'; +// $dsn = './scripted.db'; +$dsn = 'C:\\wamp64\\www\\scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/Model/AdminModel.php b/Model/AdminModel.php index 06d0e220..b23c1d72 100644 --- a/Model/AdminModel.php +++ b/Model/AdminModel.php @@ -29,22 +29,6 @@ class AdminModel $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt); $this->enigme_gateway->insert($enigme); $tabEnigme = $this->enigme_gateway->findLastEnigma(); - $js = fopen("View/src/JS/$nom.js", "w"); - if (is_resource($js)) { - fwrite($js, "//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\\n\n". $solution . "\n". $test . "\n`; - exec(\"print ('True')\", \"code\"); - exec(test, \"solution\"); - result.innerHTML = \"Test en cours...\"; - await new Promise(r => setTimeout(r, 1500)); - check(); -}"); - fclose($js); - } else { - throw new Exception("Impossible d'ouvrir le fichier"); - } return $tabEnigme[0]; } public function addNewEnigmeMulti(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution, string $prompt, int $points, int $tempsDeResolution) : Enigme @@ -52,22 +36,6 @@ async function submit(){ $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, 0, $tempsDeResolution, $points, $prompt); $this->enigme_gateway->insert($enigme); $tabEnigme = $this->enigme_gateway->findLastEnigma(); - $js = fopen("View/src/JS/$nom.js", "w"); - if (is_resource($js)) { - fwrite($js, "//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\\n\n". $solution . "\n". $test . "\n`; - exec(\"print ('True')\", \"code\"); - exec(test, \"solution\"); - result.innerHTML = \"Test en cours...\"; - await new Promise(r => setTimeout(r, 1500)); - check(); -}"); - fclose($js); - } else { - throw new Exception("Impossible d'ouvrir le fichier"); - } return $tabEnigme[0]; } @@ -97,7 +65,6 @@ async function submit(){ $this->resoudre_gateway->deleteByEnigme($id); $this->partie_gateway->deleteByEnigme($id); $this->enigme_gateway->delete($id); - unlink('View/src/JS/'.$nom.'.js'); $this->majOrdreAfterDelete($ordre); } @@ -127,25 +94,6 @@ async function submit(){ $prompt = trim($prompt); $enigme = new Enigme($id,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, $tempsDeResolution, $points, $prompt); $this->enigme_gateway->update($enigme); - $js = fopen("View/src/JS/$nom.js", "w"); - if (is_resource($js)) { - fwrite($js, "//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\\n\n". $solution . "\n". $test . "\n`; - exec(\"print ('True')\", \"code\"); - exec(test, \"solution\"); - result.innerHTML = \"Test en cours...\"; - await new Promise(r => setTimeout(r, 1500)); - check(); -}"); - fclose($js); - if ($old->getNom() != $nom){ - unlink('View/src/JS/'.$old->getNom().'.js'); - } - } else { - throw new Exception("Impossible d'ouvrir le fichier"); - } return $enigme; } diff --git a/View/src/JS/CesarDecrypt.js b/View/src/JS/CesarDecrypt.js deleted file mode 100644 index 70865298..00000000 --- a/View/src/JS/CesarDecrypt.js +++ /dev/null @@ -1,41 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def DecryptVerif(text, key): - result = "" - for i in range(len(text)): - char = text[i] - if(char==" "): - result+=" " - elif (char.isupper()): - result += chr((ord(char) - key-65) % 26 + 65) - else: - result += chr((ord(char) - key - 97) % 26 + 97) - return result - -import random as r -def testDecrypte(x): - Decrypt("",1) - if(Decrypt("Jgnnq yqtnf",2)!="Hello world"): - return False - if(Decrypt("Blarycnm",9)!="Scripted"): - return False - for i in range(x): - l="" - cle=r.randint(1,26) - for i in range(r.randint(1,10)): - l+=chr(r.randint(97,122)) - if(Decrypt(l,cle)!=DecryptVerif(l,cle)): - return False - return True - -print(testDecrypte(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); - } - \ No newline at end of file diff --git a/View/src/JS/CesarEncrypt.js b/View/src/JS/CesarEncrypt.js deleted file mode 100644 index 4268a506..00000000 --- a/View/src/JS/CesarEncrypt.js +++ /dev/null @@ -1,41 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def EncryptVerif(text, key): - result = "" - for i in range(len(text)): - char = text[i] - if(char==" "): - result+=" " - elif (char.isupper()): - result += chr((ord(char) + key-65) % 26 + 65) - else: - result += chr((ord(char) + key - 97) % 26 + 97) - return result - -import random as r -def testEncrypte(x): - Encrypt("",1) - if(Encrypt("Hello world",2)!="Jgnnq yqtnf"): - return False - if(Encrypt("Scripted",9)!="Blarycnm"): - return False - for i in range(x): - l="" - cle=r.randint(1,26) - for i in range(r.randint(1,10)): - l+=chr(r.randint(97,122)) - if(Encrypt(l,cle)!=EncryptVerif(l,cle)): - return False - return True - -print(testEncrypte(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); - } - \ No newline at end of file diff --git a/View/src/JS/Chouette.js b/View/src/JS/Chouette.js deleted file mode 100644 index 084e34f9..00000000 --- a/View/src/JS/Chouette.js +++ /dev/null @@ -1,31 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def chouetteVerif(valeur): - res=list() - for i in range(1, 7): - for j in range(i, 7): - for k in range(j, 7): - if (i+j+k) == valeur: - res.append([i, j, k]) - return res -import random as r -def test_chouette(n): - chouette(1) - listTest=[] - for i in range(0,n): - listTest.append(r.randint(3,18)) - for i in listTest: - if(chouette(i)!=chouetteVerif(i)): - return False - return True - -print(test_chouette(5)) -`; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); -} \ No newline at end of file diff --git a/View/src/JS/ChuckNorris.js b/View/src/JS/ChuckNorris.js deleted file mode 100644 index fd142367..00000000 --- a/View/src/JS/ChuckNorris.js +++ /dev/null @@ -1,59 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def binaire2unitaireVerif(x): - rep=0 - pre=x[0] - unitaire="" - for i in x: - if(pre==i): - rep+=1 - else: - if(pre=="1"): - unitaire=unitaire+"0 " - else: - unitaire=unitaire+"00 " - for j in range(rep): - unitaire=unitaire+"0" - unitaire=unitaire+" " - rep=1 - pre=i - if(pre=="1"): - unitaire=unitaire+"0 " - else: - unitaire=unitaire+"00 " - for i in range(rep): - unitaire=unitaire+"0" - return unitaire - -import random as r -def testChuckNorris(x): - l="0000000" - binaire2unitaire(l) - if(binaire2unitaire(l)!="00 0000000"): - return False - l="1111111" - if(binaire2unitaire(l)!="0 0000000"): - return False - l="1101001" - if(binaire2unitaire(l)!="0 00 00 0 0 0 00 00 0 0"): - return False - l="" - for i in range(x): - for j in range(r.randint(1,10)): - l=l+str(r.randint(0,1)) - if(binaire2unitaire(l)!=binaire2unitaireVerif(l)): - return False - l="" - return True - -print(testChuckNorris(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); -} - diff --git a/View/src/JS/Const.js b/View/src/JS/Const.js new file mode 100644 index 00000000..9069a69d --- /dev/null +++ b/View/src/JS/Const.js @@ -0,0 +1,5 @@ +// const URL = "http://localhost/Scripted/index.php"; +// const URL = "http://82.165.180.114/Scripted/index.php"; +// const URL = "http://sancy.iut.uca.fr/~lafourcade/Scripted/index.php"; + +// Constant use in base.js and baseTest.js and Partie.php \ No newline at end of file diff --git a/View/src/JS/DoubleElement.js b/View/src/JS/DoubleElement.js deleted file mode 100644 index 8aa398cc..00000000 --- a/View/src/JS/DoubleElement.js +++ /dev/null @@ -1,34 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def double_elementVerif(list): - return [i*2 for i in list] - -import random as r -def testDoubleElement(x): - l=[1,2,3,2,1] - if(double_element(l) != [2,4,6,4,2]): - return False - l=[9,5,7,7,9] - if(double_element(l) != [18,10,14,14,18]): - return False - l=[] - for i in range(x): - for j in range(r.randint(1,10)): - l.append(r.randint(0,9)) - if(double_elementVerif(l)!=double_element(l)): - return False - l=[] - return True - -print(testDoubleElement(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); - } - - \ No newline at end of file diff --git a/View/src/JS/Hanoi.js b/View/src/JS/Hanoi.js deleted file mode 100644 index fcab32ef..00000000 --- a/View/src/JS/Hanoi.js +++ /dev/null @@ -1,38 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def hanoi_rec(l,nb_disks, start, middle, end): - if(nb_disks == 1): - return l.append([start,end]) - else: - hanoi_rec(l,nb_disks - 1, start, end, middle) - l.append([start,end]) - hanoi_rec(l,nb_disks - 1, middle, start, end) - -def hanoiVerif(nb_disks,start, middle, end): - l=[] - hanoi_rec(l,nb_disks,start, middle, end) - return l - -import random as r -def testhanoi(x): - hanoi(1,"A","B","C") - if(hanoi(3,"A","B","C")!=[['A','C'],['A','B'],['C','B'],['A','C'],['B','A'],['B','C'],['A','C']]): - return False - for i in range(x): - j=r.randint(1,4) - if(hanoi(j,"Z","E","R")!=hanoiVerif(j,"Z","E","R")): - return False - return True - -print(testhanoi(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); -} - - \ No newline at end of file diff --git a/View/src/JS/Palindrome.js b/View/src/JS/Palindrome.js deleted file mode 100644 index 141d35ad..00000000 --- a/View/src/JS/Palindrome.js +++ /dev/null @@ -1,34 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def estPalindromeVerif(var): - if(var == var[::-1]): - return True - else: - return False -import random as r -def testPalindrome(x): - l=[1,2,3,2,1] - if(estPalindrome(l)==False): - return False - l=[9,5,7,7,9] - if(estPalindrome(l)==True): - return False - l=[] - for i in range(x): - for j in range(r.randint(1,10)): - l.append(r.randint(0,9)) - if(estPalindromeVerif(l)!=estPalindrome(l)): - return False - l=[] - return True - -print(testPalindrome(5)) -`; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); -} \ No newline at end of file diff --git a/View/src/JS/Submit.js b/View/src/JS/Submit.js new file mode 100644 index 00000000..e5f745f0 --- /dev/null +++ b/View/src/JS/Submit.js @@ -0,0 +1,10 @@ +//~ Function that test the user code + +async function submit(solution, test){ + var test = editor.getValue()+`\n` + solution + `\n` + test; + exec("print ('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); +} \ No newline at end of file diff --git a/View/src/JS/TrianglePascal.js b/View/src/JS/TrianglePascal.js deleted file mode 100644 index 938fbcb6..00000000 --- a/View/src/JS/TrianglePascal.js +++ /dev/null @@ -1,39 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue()+`\n -def estTriangleDePascal(n): - if(n==0): - return [] - if(n==1): - return [[1]] - triangle=[[1],[1, 1]] - columns=n - for line in range(2,n): - triangle.append([1]) - for column in range(1, line): - triangle[line].append(triangle[line - 1][column - 1] + triangle[line - 1][column]) - triangle[line].append(1) - return triangle - -import random as r -def testTriangleDePascal(n): - triangle_pascal(0) - listTest=[0,1] - for i in range(0,n): - listTest.append(r.randint(5,140)) - for i in listTest: - if(triangle_pascal(i)!=estTriangleDePascal(i)): - return False - return True - -print(testTriangleDePascal(5)) - `; - exec("print ('True')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); -} - - \ No newline at end of file diff --git a/View/src/JS/base.js b/View/src/JS/base.js index c6f4ca18..1dbe44f6 100644 --- a/View/src/JS/base.js +++ b/View/src/JS/base.js @@ -1,3 +1,7 @@ +// const URL = "http://localhost/Scripted/index.php"; +const URL = "http://82.165.180.114/Scripted/index.php"; +// const URL = "http://sancy.iut.uca.fr/~lafourcade/Scripted/index.php"; + function run() { const terminal = document.getElementById("console"); const runner = new BrythonRunner({ @@ -131,8 +135,7 @@ function displayHelp() { function saveCode() { var xhr = new XMLHttpRequest(); - // xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=saveCode', true); + xhr.open('POST', URL +'?action=saveCode', true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function () { diff --git a/View/src/JS/baseTest.js b/View/src/JS/baseTest.js index 8143d46a..f3e8a299 100644 --- a/View/src/JS/baseTest.js +++ b/View/src/JS/baseTest.js @@ -1,3 +1,7 @@ +// const URL = "http://localhost/Scripted/index.php"; +const URL = "http://82.165.180.114/Scripted/index.php"; +// const URL = "http://sancy.iut.uca.fr/~lafourcade/Scripted/index.php"; + function run() { const terminal = document.getElementById("console"); const runner = new BrythonRunner({ @@ -131,8 +135,7 @@ function run() { function saveCode() { var xhr = new XMLHttpRequest(); - // xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCodeInCookie', true); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=saveCodeInCookie', true); + xhr.open('POST', URL + '?action=saveCodeInCookie', true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function () { diff --git a/View/src/pages/Enigme/EnigmePage.php b/View/src/pages/Enigme/EnigmePage.php index e71eb081..a83150be 100644 --- a/View/src/pages/Enigme/EnigmePage.php +++ b/View/src/pages/Enigme/EnigmePage.php @@ -122,7 +122,7 @@
-
@@ -170,8 +170,16 @@ + getNom() . '.js">'; + echo ''; ?> diff --git a/View/src/pages/Multijoueur/Partie.php b/View/src/pages/Multijoueur/Partie.php index ab85b4ea..b9a78314 100644 --- a/View/src/pages/Multijoueur/Partie.php +++ b/View/src/pages/Multijoueur/Partie.php @@ -172,13 +172,16 @@ + getNom() . '.js">'; + echo ''; ?>