96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
namespace nur\v\vp;
|
|
|
|
use nur\authz;
|
|
use nur\F;
|
|
use nur\msg;
|
|
use nur\P;
|
|
use nur\v\fo;
|
|
use nur\v\ly;
|
|
use nur\v\page;
|
|
use nur\v\v;
|
|
|
|
trait TFormLoginPage {
|
|
function TLoginPage_afterConfig(): void {
|
|
# initialiser la session avant setup. ainsi, dans les fonction beforeSetup(),
|
|
# setup() et afterSetup(), la session est disponible
|
|
$username = P::get("u");
|
|
$password = P::get("p");
|
|
$destPage = F::get("d", $this->getMainUrl());
|
|
$this->ensureFormLoginAndRedirect($username, $password, $destPage);
|
|
|
|
authz::manager()->checkSession($flcUsername, $flcAuthType);
|
|
$this->flcUsername = $flcUsername;
|
|
$this->flcAuthType = $flcAuthType;
|
|
}
|
|
function afterConfig(): void {
|
|
$this->TLoginPage_afterConfig();
|
|
parent::afterConfig();
|
|
}
|
|
|
|
private $flcUsername = null;
|
|
private $flcAuthType = null;
|
|
|
|
function print(): void {
|
|
page::no_cache();
|
|
$username = P::get("u");
|
|
$password = P::get("p");
|
|
|
|
ly::row();
|
|
$this->printTitle();
|
|
|
|
ly::col(["sm" => 6, "sm-push" => 3]);
|
|
$status = authz::get_status();
|
|
switch ($status) {
|
|
case authz::DISCONNECTED:
|
|
msg::warning("Vous avez été déconnecté. Veuillez vous reconnecter");
|
|
break;
|
|
case authz::UNAUTHORIZED:
|
|
msg::error(["user" => [
|
|
"Connecté en tant que ",
|
|
v::b(authz::get_auth()),
|
|
", vous n'êtes pas autorisé à accéder à la page que vous avez demandé.",
|
|
]]);
|
|
break;
|
|
}
|
|
|
|
ly::panel("Connexion par identifiant/mot de passe");
|
|
fo::start([
|
|
"type" => "basic",
|
|
"action" => "",
|
|
"method" => "post",
|
|
]);
|
|
fo::text("Identifiant", "u", $username?: $this->flcUsername, [
|
|
"accesskey" => "q",
|
|
"placeholder" => "Votre identifiant",
|
|
]);
|
|
fo::password("Mot de passe", "p", $password, [
|
|
"placeholder" => "Votre mot de passe",
|
|
]);
|
|
if ($username || $password) {
|
|
msg::error("$username: Votre identifiant et/ou votre mot de passe sont incorrects");
|
|
} elseif ($username === "") {
|
|
msg::error("Vous devez saisir votre identifiant");
|
|
} elseif ($password === "") {
|
|
msg::error("Vous devez saisir votre mot de passe");
|
|
}
|
|
fo::submit(["Connexion", "accesskey" => "r"]);
|
|
if (authz::is_auth() && $this->flcAuthType === "form") {
|
|
if ($status != authz::UNAUTHORIZED) {
|
|
msg::warning(["user" => [
|
|
"Connecté en tant que ",
|
|
v::b(authz::get_auth()),
|
|
", vous n'êtes pas autorisé à accéder à cette application.",
|
|
]]);
|
|
}
|
|
fo::submit([
|
|
"Vous déconnecter", "accesskey" => "z",
|
|
"formmethod" => "get", "formaction" => $this->getLogoutUrl(),
|
|
]);
|
|
}
|
|
fo::end();
|
|
|
|
ly::end();
|
|
}
|
|
}
|