feat : liaison php/Blazor
continuous-integration/drone/push Build is passing Details

Multiplayer_Php
Yvan CALATAYUD 1 year ago
parent 3cd53c8477
commit 52df7402f5

@ -9,3 +9,5 @@
<h1 class="text-center">@Localizer["Title"]</h1> <h1 class="text-center">@Localizer["Title"]</h1>
<p class="text-center">@Localizer["Text"]</p> <p class="text-center">@Localizer["Text"]</p>
<button type="button" class="btn btn-primary mb-2" @onclick="CloseApplication">Fermer l'application</button>

@ -8,5 +8,17 @@ namespace Blazor.Pages
{ {
[Inject] [Inject]
public IStringLocalizer<Index> Localizer { get; set; } public IStringLocalizer<Index> Localizer { get; set; }
[Inject]
public IHostApplicationLifetime AppLifetime { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
private void CloseApplication()
{
NavigationManager.NavigateTo("http://localhost", forceLoad: true);
AppLifetime.StopApplication();
}
} }
} }

@ -24,6 +24,9 @@ class ControllerUser
private $twig; private $twig;
private $vues; private $vues;
private $blazorAppPath = '..\Blazor\Blazor'; // Remplacez par le chemin réel vers votre projet Blazor
private $blazorPort = 5234; // Remplacez par le port utilisé par votre projet Blazor
function __construct() function __construct()
{ {
global $vues, $twig; global $vues, $twig;
@ -81,7 +84,7 @@ class ControllerUser
function loginAdmin() function loginAdmin()
{ {
if ($_SESSION["idAdminConnected"] != null) { if ($_SESSION["idAdminConnected"] != null) {
header("Location:/admin/administrators"); $this->launchBlazor();
} }
echo $this->twig->render($this->vues["loginAdmin"], [ echo $this->twig->render($this->vues["loginAdmin"], [
@ -127,6 +130,32 @@ class ControllerUser
} }
} }
function launchBlazor(){
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$command = 'cd ..\Blazor\Blazor && dotnet run --urls=http://0.0.0.0:5234';
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
fclose($pipes[0]);
fclose($pipes[2]);
fclose($pipes[1]);
sleep(2);
header('Location: http://localhost:5234/');
exit();
} else {
// Handle the error
echo "Erreur lors du lancement de l'application Blazor.";
}
}
function verifyAdmin() function verifyAdmin()
{ {
$username = $_POST['username']; $username = $_POST['username'];
@ -140,7 +169,8 @@ class ControllerUser
$AdministratorIsOk = $this->mdAdministrator->verifyAdministrator($Administrator); $AdministratorIsOk = $this->mdAdministrator->verifyAdministrator($Administrator);
if ($AdministratorIsOk != null) { if ($AdministratorIsOk != null) {
$_SESSION["idAdminConnected"] = $AdministratorIsOk; $_SESSION["idAdminConnected"] = $AdministratorIsOk;
header("Location:/admin/administrators"); $this->launchBlazor();
} else { } else {
$_SESSION["error"] = "utilisateur introuvable."; $_SESSION["error"] = "utilisateur introuvable.";
header("Location:/loginAdmin"); header("Location:/loginAdmin");

Loading…
Cancel
Save