2
0

index.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. session_start();
  3. require_once "../../../env.inc.php";
  4. require_once DOCUMENT_ROOT."/access.inc.php";
  5. require_once DOCUMENT_ROOT."/conf.inc.php";
  6. require_once DIR_PHP_LAYOUTS . "header.php";
  7. if(core::ifPost("email") AND core::ifPost("password")){
  8. $connect = user::authenticator(core::getPost());
  9. if($connect["status"] == "success"){
  10. historique::recRef("/api/authenticator/");
  11. historique::add(array(
  12. "idType" => historique::getIdRef("CONNEXION"),
  13. "idUser" => $connect["id"],
  14. "idPage" => historique::getIdRef("/api/authenticator/"),
  15. "log" => $_SERVER['REMOTE_ADDR']
  16. ));
  17. // Réponse JSON en cas de succès
  18. echo json_encode([
  19. "status" => $connect["status"],
  20. "message" => "Login successful",
  21. "session_id" => session_id(),
  22. "type" => $connect["type"],
  23. "id" => $connect["id"],
  24. "prenom" => $connect["prenom"],
  25. "nom" => $connect["nom"],
  26. "googleAuthenticator" => $connect["googleAuthenticator"],
  27. "idType" => $connect["idType"],
  28. "email" => $connect["email"]
  29. ]);
  30. }
  31. else {
  32. // Authentification échouée
  33. http_response_code(401); // Code 401 Unauthorized
  34. echo json_encode([
  35. "status" => "error",
  36. "message" => "Invalid email or password"
  37. ]);
  38. }
  39. }