SessionHttp.php (mrbs-1.9.4) | : | SessionHttp.php (mrbs-1.10.0) | ||
---|---|---|---|---|
<?php | <?php | |||
namespace MRBS\Session; | namespace MRBS\Session; | |||
use MRBS\User; | ||||
// Get user identity using the HTTP basic authentication | // Get user identity using the HTTP basic authentication | |||
class SessionHttp extends SessionWithLogin | class SessionHttp extends SessionWithLogin | |||
{ | { | |||
public function authGet($target_url=null, $returl=null, $error=null, $raw=fals e) | public function authGet(?string $target_url=null, ?string $returl=null, ?strin g $error=null, bool $raw=false) : void | |||
{ | { | |||
global $auth; | global $auth; | |||
header("WWW-Authenticate: Basic realm=\"$auth[realm]\""); | header("WWW-Authenticate: Basic realm=\"$auth[realm]\""); | |||
header("HTTP/1.0 401 Unauthorized"); | header("HTTP/1.0 401 Unauthorized"); | |||
} | } | |||
public function getCurrentUser() | public function getCurrentUser() : ?User | |||
{ | { | |||
global $server; | global $server; | |||
if (!isset($server['PHP_AUTH_USER'])) | if (!isset($server['PHP_AUTH_USER'])) | |||
{ | { | |||
return null; | return null; | |||
} | } | |||
// Trim any whitespace because PHP_AUTH_USER can contain it. | // Trim any whitespace because PHP_AUTH_USER can contain it. | |||
$php_auth_user = trim($server['PHP_AUTH_USER']); | $php_auth_user = trim($server['PHP_AUTH_USER']); | |||
skipping to change at line 42 | skipping to change at line 44 | |||
} | } | |||
if (\MRBS\auth()->validateUser($php_auth_user, self::getAuthPassword()) === false) | if (\MRBS\auth()->validateUser($php_auth_user, self::getAuthPassword()) === false) | |||
{ | { | |||
return null; | return null; | |||
} | } | |||
return \MRBS\auth()->getUser($php_auth_user); | return \MRBS\auth()->getUser($php_auth_user); | |||
} | } | |||
public function getLogoffFormParams() | public function getLogoffFormParams() : ?array | |||
{ | { | |||
// Just return NULL - you can't logoff | // Just return null - you can't logoff | |||
// (well, there are ways of achieving a logoff but we haven't implemented th em) | // (well, there are ways of achieving a logoff but we haven't implemented th em) | |||
return null; | ||||
} | } | |||
private static function getAuthPassword() | private static function getAuthPassword() : ?string | |||
{ | { | |||
global $server; | global $server; | |||
return (isset($server['PHP_AUTH_PW'])) ? $server['PHP_AUTH_PW'] : null; | return (isset($server['PHP_AUTH_PW'])) ? $server['PHP_AUTH_PW'] : null; | |||
} | } | |||
} | } | |||
End of changes. 7 change blocks. | ||||
5 lines changed or deleted | 8 lines changed or added |