git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1207 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
/** Takes the email and the password of the user */
|
|
class authparams
|
|
{
|
|
/** Get informations from $POST variables */
|
|
public function post()
|
|
{
|
|
if (!isset ($_POST["email"]) || !isset ($_POST["password"]))
|
|
throw new Exception ("No POST provided", 401);
|
|
return array ("email"=>$_POST["email"], "password"=>$_POST["password"]);
|
|
}
|
|
|
|
/** Get informations from previous recorded session */
|
|
public function session()
|
|
{
|
|
if (!isset ($_SESSION))
|
|
throw new Exception ("No session previously opened", 401);
|
|
if (!isset ($_SESSION["auth"]["email"]) ||
|
|
!isset ($_SESSION["auth"]["password"]))
|
|
throw new Exception ("No previous email in session", 401);
|
|
return array ("email"=>$_SESSION["auth"]["email"],
|
|
"password"=>$_SESSION["auth"]["email"]);
|
|
}
|
|
|
|
/** Get informations from a HTTP authentication */
|
|
public function http()
|
|
{
|
|
$realm = _("Restricted access");
|
|
if (!isset($_SERVER['PHP_AUTH_USER']))
|
|
{
|
|
header("WWW-Authenticate: Basic realm=\"$realm\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
die ($realm);
|
|
}
|
|
else
|
|
{
|
|
return array ("email"=>$_SERVER["PHP_AUTH_USER"],
|
|
"password"=>$_SERVER["PHP_AUTH_PW"]);
|
|
}
|
|
}
|
|
}
|