111 lines
3.0 KiB
PHP
111 lines
3.0 KiB
PHP
|
<?php
|
||
|
namespace nur\v\vp;
|
||
|
|
||
|
use nur\authz;
|
||
|
use nur\config;
|
||
|
use nur\F;
|
||
|
use nur\msg;
|
||
|
use nur\v\fo;
|
||
|
use nur\v\icon;
|
||
|
use nur\v\ly;
|
||
|
use nur\v\page;
|
||
|
use nur\v\v;
|
||
|
use nur\v\vo;
|
||
|
|
||
|
trait TCasLoginPage {
|
||
|
function TLoginPage_afterConfig(): void {
|
||
|
# initialiser la session avant setup. ainsi, dans les fonction beforeSetup(),
|
||
|
# setup() et afterSetup(), la session est disponible
|
||
|
$this->flDestPage = F::get("d", $this->getMainUrl());
|
||
|
authz::manager()->checkSession($flcUsername, $flcAuthType);
|
||
|
|
||
|
if ($flcAuthType === "cas" && F::get("a")) {
|
||
|
# autologin
|
||
|
$casauthUrl = config::k("url")."/".$this->getCasauthUrl();
|
||
|
page::redirect(page::bu($this->getCasLoginUrl(), [
|
||
|
"service" => page::bu($casauthUrl, [
|
||
|
"r" => $this->getLoginUrl(),
|
||
|
"d" => $this->flDestPage,
|
||
|
])
|
||
|
]));
|
||
|
}
|
||
|
$this->flcAuthType = $flcAuthType;
|
||
|
}
|
||
|
function afterConfig(): void {
|
||
|
$this->TLoginPage_afterConfig();
|
||
|
parent::afterConfig();
|
||
|
}
|
||
|
|
||
|
private $flDestPage = null;
|
||
|
private $flcAuthType = null;
|
||
|
|
||
|
function print(): void {
|
||
|
page::no_cache();
|
||
|
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 CAS");
|
||
|
if ($this->isDevauthAllowed()) {
|
||
|
fo::start([
|
||
|
"type" => "basic",
|
||
|
"action" => $this->getCasauthUrl(),
|
||
|
"method" => "get",
|
||
|
]);
|
||
|
fo::hidden("r", $this->getLoginUrl());
|
||
|
fo::hidden("d", $this->flDestPage);
|
||
|
} else {
|
||
|
fo::start([
|
||
|
"type" => "basic",
|
||
|
"action" => $this->getCasLoginUrl(),
|
||
|
"method" => "get",
|
||
|
]);
|
||
|
$casauthUrl = config::k("url")."/".$this->getCasauthUrl();
|
||
|
fo::hidden("service", page::bu($casauthUrl, [
|
||
|
"r" => $this->getLoginUrl(),
|
||
|
"d" => $this->flDestPage,
|
||
|
]));
|
||
|
}
|
||
|
#fo::p("Si vous avez un compte à l'université, vous pouvez vous connecter via CAS");
|
||
|
vo::p("Si vous avez un compte à l'université, vous pouvez vous connecter via CAS");
|
||
|
if (authz::is_auth()) {
|
||
|
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([
|
||
|
icon::logout("Vous déconnecter"),
|
||
|
"formaction" => $this->getLogoutUrl(),
|
||
|
"accesskey" => "z",
|
||
|
]);
|
||
|
fo::hidden("renew", "true");
|
||
|
fo::submit([
|
||
|
icon::login("Changer de compte"),
|
||
|
"accesskey" => "r",
|
||
|
]);
|
||
|
} else {
|
||
|
fo::submit(["Connexion par CAS", "accesskey" => "r"]);
|
||
|
}
|
||
|
fo::end();
|
||
|
|
||
|
ly::end();
|
||
|
}
|
||
|
}
|