mirror of
https://github.com/BreizhHardware/ProjetS4COMWEB.git
synced 2026-01-18 16:47:35 +01:00
Add Login Backend
This commit is contained in:
@@ -4,6 +4,7 @@ require_once 'src/router.php';
|
||||
require_once '../php/constants.php';
|
||||
require_once '../php/db/dbconnect.php';
|
||||
require_once '../php/db/Search.php';
|
||||
require_once '../php/db/Login.php';
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
$pdo = dbConnect();
|
||||
@@ -20,6 +21,7 @@ $router->GET('/api/search', ["type"], function($type){
|
||||
searchDoctor($pdo, $type);
|
||||
});
|
||||
|
||||
/*
|
||||
$router->GET('/api/search', ["type", "location"], function($type, $location){
|
||||
global $pdo;
|
||||
searchDoctorByLocation($pdo, $location, $type);
|
||||
@@ -29,12 +31,20 @@ $router->GET('/api/search', ["location"], function($location){
|
||||
global $pdo;
|
||||
searchDoctorByLocation($pdo, $location);
|
||||
});
|
||||
|
||||
|
||||
*/
|
||||
$router->POST('/api/requests', ["test"], function($test){
|
||||
echo json_encode($test);
|
||||
});
|
||||
|
||||
$router->POST('/api/login/patient', ["mail", "password"], function($mail, $password){
|
||||
global $pdo;
|
||||
loginPatient::Login($pdo, $mail, $password);
|
||||
});
|
||||
|
||||
$router->POST('/api/login/medecin', ["mail", "password"], function($mail, $password){
|
||||
global $pdo;
|
||||
loginMedecin::Login($pdo, $mail, $password);
|
||||
});
|
||||
$router->PUT('/api/requests', ["test"], function($test){
|
||||
echo json_encode($test);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
//require_once '../../API/src/response.php';
|
||||
/*
|
||||
class LoginPatient {
|
||||
|
||||
public static function checkMail($pdo, $mail) {
|
||||
@@ -77,4 +80,71 @@ class LoginMedecin {
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
*/
|
||||
|
||||
class LoginPatient {
|
||||
public static function checkMail($pdo, $mail) : bool
|
||||
{
|
||||
$query = $pdo->prepare("SELECT COUNT(*) as count FROM patient WHERE p_mail = :mail");
|
||||
$query->bindParam(':mail', $mail);
|
||||
$query->execute();
|
||||
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result['count'] == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function Login($pdo,$mail,$password) : void
|
||||
{
|
||||
if(LoginPatient::checkMail($pdo,$mail)){
|
||||
$query = $pdo->prepare("SELECT p_id,p_password FROM patient where p_mail = :mail");
|
||||
$query->bindParam(':mail', $mail);
|
||||
$query->execute();
|
||||
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if(password_verify($password,$result['p_password'])){
|
||||
Response::HTTP200(['message' => 'Login success', 'id' => $result['p_id']]);
|
||||
} else {
|
||||
Response::HTTP401(['message' => 'Login failed', 'id' => 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LoginMedecin {
|
||||
public static function checkMail($pdo, $mail) : bool
|
||||
{
|
||||
$query = $pdo->prepare("SELECT COUNT(*) as count FROM medecin WHERE m_mail = :mail");
|
||||
$query->bindParam(':mail', $mail);
|
||||
$query->execute();
|
||||
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result['count'] == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function Login($pdo,$mail,$password) : void
|
||||
{
|
||||
if(LoginMedecin::checkMail($pdo,$mail)){
|
||||
$query = $pdo->prepare("SELECT m_id, m_password FROM medecin where m_mail = :mail");
|
||||
$query->bindParam(':mail', $mail);
|
||||
$query->execute();
|
||||
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if(password_verify($password,$result['m_password'])){
|
||||
Response::HTTP200(['message' => 'Login success', 'id' => $result['m_id']]);
|
||||
} else {
|
||||
Response::HTTP401(['message' => 'Login failed', 'id' => 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user