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;
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\Validate;
use Exceptions\InvalidUsernameOrPasswordException;
use Exception;
use Exceptions\InvalidLoginOrPasswordException;
use Exceptions\InexistantLoginException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* Permet de développer les fonctions appelées par le controllerCandidate pour gérer
@ -18,10 +16,18 @@ use Exceptions\InexistantLoginException;
*/
class ModelCandidate
{
private Client $client;
public function __construct(){
$this->client = new Client();
}
/**
* Permet de soumettre et d'envoyer la réponse à un formulaire.
*
* @return void
* @throws Exception
*/
public function submitForm(): void
{
@ -52,29 +58,48 @@ class ModelCandidate
$category[] = [];
}
}
$title = (new GatewayForm())->getForm()[0]["title"];
(new GatewayListResponseOfCandidate())->insertListResponsesOfCandidate($questionsId, $answer, $category, $title);
try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm');
$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,
* 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
* pour récupèrer les questions.
* On les traduit en code HTML puis on le retourne. On utilise une Factory
* pour récupérer les questions.
*
* @return string
* @throws Exception
*/
public function getForm(): string
{
$form = (new GatewayForm())->getForm();
if (empty($form)) {
return "PAS DE FORMULAIRE\n";
}
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)) {
return "PAS DE FORMULAIRE\n";
}
$title = $form[0]['title'];
$description = $form[0]['description'];
$questionsTab = (new GatewayQuestion())->getAllQuestions($form[0]['id']);
$title = $form[0]['title'];
$description = $form[0]['description'];
$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");
@ -88,9 +113,7 @@ class ModelCandidate
<h1 id='register'>$title</h1>
<div class='all-steps' id='all-steps'>";
for ($i = 0; $i < sizeof($questions); $i++) {
$html.= "<span class='step'><i class='fa'></i></span>";
}
$html .= str_repeat("<span class='step'><i class='fa'></i></span>", sizeof($questions));
$html.= "</div>";
foreach ($questions as $question) {
@ -98,7 +121,7 @@ class ModelCandidate
}
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>
<input type='hidden' name='data_ids' value=''>
<input type='submit' value='Envoyer' id='button'>\n
@ -120,21 +143,35 @@ class ModelCandidate
return $html;
}
/**
* @throws InvalidLoginOrPasswordException
* @throws InexistantLoginException
* @throws Exception
*/
public function login() :void {
global $rep,$views,$sel;
$password = Clean::simpleString($_REQUEST['password']);
$identifiant = Clean::simpleString($_REQUEST['login']);
$gatewayAdmin = new GatewayAdmin();
if (Validate::login($identifiant) && Validate::password($password)){
$passwordbdd=$gatewayAdmin->getPasswordWithLogin($identifiant);
if($passwordbdd==null) throw new InexistantLoginException();
if(password_verify($sel . $password,$passwordbdd)) {
$_SESSION['role'] = 'Admin';
try {
if (Validate::login($identifiant) && Validate::password($password)) {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getPasswordWithLogin?
login='.$identifiant
);
$passwordbdd = json_decode($res->getBody());
if ($passwordbdd == null) {
throw new InexistantLoginException();
}
if (password_verify($sel . $password, $passwordbdd)) {
$_SESSION['role'] = 'Admin';
} else {
$_SESSION['role'] = 'Visitor';
}
} else {
$_SESSION['role'] = 'Visitor';
throw new InvalidLoginOrPasswordException();
}
}catch (GuzzleException $g){
throw new Exception($g->getMessage(),$g->getCode(),$g);
}
else throw new InvalidLoginOrPasswordException();
}
}

Loading…
Cancel
Save