Finalize call of API in ModelCandidate.php, modify GitIgnore
continuous-integration/drone/push Build is passing Details

interestingProfiles
dorian.hodin 2 years ago
parent aac0f99592
commit 5f13e26ddd

1
.gitignore vendored

@ -1 +0,0 @@
./Source/Config/vendor/

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@localhost" uuid="31f3a16e-d54b-4596-809a-37bbd2defc86">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

1
Source/.gitignore vendored

@ -0,0 +1 @@
/Config/vendor/

@ -2,15 +2,13 @@
namespace Model; namespace Model;
use API\script\Gateway\GatewayForm;
use API\script\Gateway\GatewayListResponseOfCandidate;
use API\script\Gateway\GatewayQuestion;
use API\script\Gateway\GatewayAdmin;
use Config\Clean; use Config\Clean;
use Config\Validate; use Config\Validate;
use Exceptions\InvalidUsernameOrPasswordException; use Exception;
use Exceptions\InvalidLoginOrPasswordException; use Exceptions\InvalidLoginOrPasswordException;
use Exceptions\InexistantLoginException; use Exceptions\InexistantLoginException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/** /**
* Permet de développer les fonctions appelées par le controllerCandidate pour gérer * Permet de développer les fonctions appelées par le controllerCandidate pour gérer
@ -18,10 +16,18 @@ use Exceptions\InexistantLoginException;
*/ */
class ModelCandidate class ModelCandidate
{ {
private Client $client;
public function __construct(){
$this->client = new Client();
}
/** /**
* Permet de soumettre et d'envoyer la réponse à un formulaire. * Permet de soumettre et d'envoyer la réponse à un formulaire.
* *
* @return void * @return void
* @throws Exception
*/ */
public function submitForm(): void public function submitForm(): void
{ {
@ -52,29 +58,48 @@ class ModelCandidate
$category[] = []; $category[] = [];
} }
} }
try {
$title = (new GatewayForm())->getForm()[0]["title"]; $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
(new GatewayListResponseOfCandidate())->insertListResponsesOfCandidate($questionsId, $answer, $category, $title); $form = json_decode($res->getBody());
$title = $form[0]["title"];
$this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertListResponsesOfCandidate?
id='.implode(",",$questionsId).'&
answer='.implode(",",$answer).'&
category='.implode(",",$category).'&
titleForm='.$title
);
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
} }
/** /**
* Permet de récupérer le code html à afficher dans la page du formulaire, * Permet de récupérer le code html à afficher dans la page du formulaire,
* on récupère donc le formulaire et toutes les questions qu'il contient. * on récupère donc le formulaire et toutes les questions qu'il contient.
* On les traduits en code HTML puis on le retourne. On utilise une Factory * On les traduit en code HTML puis on le retourne. On utilise une Factory
* pour récupèrer les questions. * pour récupérer les questions.
* *
* @return string * @return string
* @throws Exception
*/ */
public function getForm(): string public function getForm(): string
{ {
$form = (new GatewayForm())->getForm(); try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
$form = json_decode($res->getBody());
if (empty($form)) { if (empty($form)) {
return "PAS DE FORMULAIRE\n"; return "PAS DE FORMULAIRE\n";
} }
$title = $form[0]['title']; $title = $form[0]['title'];
$description = $form[0]['description']; $description = $form[0]['description'];
$questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']); $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllQuestions?
idForm='.$form[0]['id']
);
$questionsTab = json_decode($res->getBody());
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
$questions = Factory::getBuiltObjects($questionsTab, "Question"); $questions = Factory::getBuiltObjects($questionsTab, "Question");
@ -88,9 +113,7 @@ class ModelCandidate
<h1 id='register'>$title</h1> <h1 id='register'>$title</h1>
<div class='all-steps' id='all-steps'>"; <div class='all-steps' id='all-steps'>";
for ($i = 0; $i < sizeof($questions); $i++) { $html .= str_repeat("<span class='step'><i class='fa'></i></span>", sizeof($questions));
$html.= "<span class='step'><i class='fa'></i></span>";
}
$html.= "</div>"; $html.= "</div>";
foreach ($questions as $question) { foreach ($questions as $question) {
@ -98,7 +121,7 @@ class ModelCandidate
} }
if (count($questions) > 0) { if (count($questions) > 0) {
$html.= "<div class='thanks-message text-center' id='text-message'> <img src='https://i.imgur.com/O18mJ1K.png' width='100' class='mb-4'> $html.= "<div class='thanks-message text-center' id='text-message'> <img src='https://i.imgur.com/O18mJ1K.png' alt='text-message' width='100' class='mb-4' >
<h3>Souhaitez-vous envoyer vos réponses ?</span> <h3>Souhaitez-vous envoyer vos réponses ?</span>
<input type='hidden' name='data_ids' value=''> <input type='hidden' name='data_ids' value=''>
<input type='submit' value='Envoyer' id='button'>\n <input type='submit' value='Envoyer' id='button'>\n
@ -120,21 +143,35 @@ class ModelCandidate
return $html; return $html;
} }
/**
* @throws InvalidLoginOrPasswordException
* @throws InexistantLoginException
* @throws Exception
*/
public function login() :void { public function login() :void {
global $rep,$views,$sel; global $rep,$views,$sel;
$password = Clean::simpleString($_REQUEST['password']); $password = Clean::simpleString($_REQUEST['password']);
$identifiant = Clean::simpleString($_REQUEST['login']); $identifiant = Clean::simpleString($_REQUEST['login']);
$gatewayAdmin = new GatewayAdmin(); try {
if (Validate::login($identifiant) && Validate::password($password)){ if (Validate::login($identifiant) && Validate::password($password)) {
$passwordbdd=$gatewayAdmin->getPasswordWithLogin($identifiant); $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getPasswordWithLogin?
if($passwordbdd==null) throw new InexistantLoginException(); login='.$identifiant
if(password_verify($sel . $password,$passwordbdd)) { );
$passwordbdd = json_decode($res->getBody());
if ($passwordbdd == null) {
throw new InexistantLoginException();
}
if (password_verify($sel . $password, $passwordbdd)) {
$_SESSION['role'] = 'Admin'; $_SESSION['role'] = 'Admin';
} else { } else {
$_SESSION['role'] = 'Visitor'; $_SESSION['role'] = 'Visitor';
} }
} else {
throw new InvalidLoginOrPasswordException();
}
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
} }
else throw new InvalidLoginOrPasswordException();
} }
} }

Loading…
Cancel
Save