Modification du gitignore +
continuous-integration/drone/push Build encountered an error Details

Généricité du js au niveaux du test et de la solution des énigme +
Gestion de constante du js (push prévu pour le serveur de test)
ServeurDeTest
Noé GARNIER 2 years ago
parent 4db5362d8c
commit f9dd96d7c0

3
.gitignore vendored

@ -16,4 +16,5 @@
/.idea /.idea
*.db *.db
/.vscode

@ -3,8 +3,8 @@
$rep = ''; $rep = '';
// BD // BD
$dsn = './scripted.db'; // $dsn = './scripted.db';
// $dsn = 'C:\\wamp64\\www\\scripted.db'; $dsn = 'C:\\wamp64\\www\\scripted.db';
//Sel de hashage //Sel de hashage
$sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong";

@ -29,22 +29,6 @@ class AdminModel
$enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt); $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt);
$this->enigme_gateway->insert($enigme); $this->enigme_gateway->insert($enigme);
$tabEnigme = $this->enigme_gateway->findLastEnigma(); $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]; 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 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); $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, 0, $tempsDeResolution, $points, $prompt);
$this->enigme_gateway->insert($enigme); $this->enigme_gateway->insert($enigme);
$tabEnigme = $this->enigme_gateway->findLastEnigma(); $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]; return $tabEnigme[0];
} }
@ -97,7 +65,6 @@ async function submit(){
$this->resoudre_gateway->deleteByEnigme($id); $this->resoudre_gateway->deleteByEnigme($id);
$this->partie_gateway->deleteByEnigme($id); $this->partie_gateway->deleteByEnigme($id);
$this->enigme_gateway->delete($id); $this->enigme_gateway->delete($id);
unlink('View/src/JS/'.$nom.'.js');
$this->majOrdreAfterDelete($ordre); $this->majOrdreAfterDelete($ordre);
} }
@ -127,25 +94,6 @@ async function submit(){
$prompt = trim($prompt); $prompt = trim($prompt);
$enigme = new Enigme($id,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, $tempsDeResolution, $points, $prompt); $enigme = new Enigme($id,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, $tempsDeResolution, $points, $prompt);
$this->enigme_gateway->update($enigme); $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; return $enigme;
} }

@ -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();
}

@ -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();
}

@ -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();
}

@ -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();
}

@ -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

@ -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();
}

@ -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();
}

@ -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();
}

@ -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();
}

@ -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();
}

@ -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() { function run() {
const terminal = document.getElementById("console"); const terminal = document.getElementById("console");
const runner = new BrythonRunner({ const runner = new BrythonRunner({
@ -131,8 +135,7 @@ function displayHelp() {
function saveCode() { function saveCode() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
// xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); xhr.open('POST', URL +'?action=saveCode', true);
xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=saveCode', true);
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () { xhr.onload = function () {

@ -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() { function run() {
const terminal = document.getElementById("console"); const terminal = document.getElementById("console");
const runner = new BrythonRunner({ const runner = new BrythonRunner({
@ -131,8 +135,7 @@ function run() {
function saveCode() { function saveCode() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
// xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCodeInCookie', true); xhr.open('POST', URL + '?action=saveCodeInCookie', true);
xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=saveCodeInCookie', true);
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () { xhr.onload = function () {

@ -122,7 +122,7 @@
</a> </a>
</div> </div>
<div class="col-6"> <div class="col-6">
<button onclick="submit()" class="btn" data-toggle="modal" data-target="#modal"> <button id="submit" class="btn" data-toggle="modal" data-target="#modal">
<span>Envoyer</span> <span>Envoyer</span>
</button> </button>
</div> </div>
@ -170,8 +170,16 @@
<script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js" <script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js"
type="text/javascript" charset="utf-8"></script> type="text/javascript" charset="utf-8"></script>
<script src="View/src/JS/base.js"></script> <script src="View/src/JS/base.js"></script>
<script src="View/src/JS/Submit.js"></script>
<?php <?php
echo '<script src="View/src/JS/' . $enigme->getNom() . '.js"></script>'; echo '<script>
let solution = `'. $enigme->getSolution() .'`;
let test = `'. $enigme->getTest() .'`;
let btnSubmit = document.querySelector("#submit");
btnSubmit.addEventListener("click", function(){
submit(solution, test);
});
</script>';
?> ?>
</body> </body>

@ -172,13 +172,16 @@
<script src="View/src/JS/baseMulti.js"> <script src="View/src/JS/baseMulti.js">
</script> </script>
<script> <script>
// 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 saveCode(index, enigmeId) { function saveCode(index, enigmeId) {
console.log("saveCode"); console.log("saveCode");
var index = '<?php echo $index; ?>'; var index = '<?php echo $index; ?>';
var enigmeId = '<?php echo $enigme->getIdEnigme(); ?>'; var enigmeId = '<?php echo $enigme->getIdEnigme(); ?>';
console.log("[Savecode]index : " + index, "[Savecode]enigmeId : " + enigmeId); console.log("[Savecode]index : " + index, "[Savecode]enigmeId : " + enigmeId);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=saveCodeMulti', true); xhr.open('POST', URL + '?action=saveCodeMulti', true);
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () { xhr.onload = function () {
@ -218,8 +221,16 @@
} }
var countdownTimer = setInterval('countdown()', 1000); var countdownTimer = setInterval('countdown()', 1000);
</script> </script>
<script src="View/src/JS/Submit.js"></script>
<?php <?php
echo '<script src="View/src/JS/' . $enigme->getNom() . '.js"></script>'; echo '<script>
let solution = `'. $enigme->getSolution() .'`;
let test = `'. $enigme->getTest() .'`;
let btnSubmit = document.querySelector("#submit");
btnSubmit.addEventListener("click", function(){
submit(solution, test);
});
</script>';
?> ?>
</body> </body>

Loading…
Cancel
Save