mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Refactor auth method: http basic > user login
This commit is contained in:
parent
bc7d4ef1c1
commit
21b9feb0ef
@ -1,16 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (RASPI_AUTH_ENABLED) {
|
||||
$user = $_SERVER['PHP_AUTH_USER'] ?? '';
|
||||
$pass = $_SERVER['PHP_AUTH_PW'] ?? '';
|
||||
|
||||
$auth = new \RaspAP\Auth\HTTPAuth;
|
||||
|
||||
if (!$auth->isLogged()) {
|
||||
if ($auth->login($user, $pass)) {
|
||||
$config = $auth->getAuthConfig();
|
||||
} else {
|
||||
$auth->authenticate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,6 @@ namespace RaspAP\Auth;
|
||||
|
||||
class HTTPAuth
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string $realm
|
||||
*/
|
||||
public $realm = 'Authentication Required';
|
||||
|
||||
/**
|
||||
* Stored login credentials
|
||||
* @var array $auth_config
|
||||
@ -57,15 +51,11 @@ class HTTPAuth
|
||||
public function authenticate()
|
||||
{
|
||||
if (!$this->isLogged()) {
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
header('WWW-Authenticate: Basic realm="'.$this->realm.'"');
|
||||
if (function_exists('http_response_code')) {
|
||||
// http_response_code will respond with proper HTTP version
|
||||
http_response_code(401);
|
||||
} else {
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
$redirectUrl = $_SERVER['REQUEST_URI'];
|
||||
if (strpos($redirectUrl, '/login') === false) {
|
||||
header('Location: /login?action=' . urlencode($redirectUrl));
|
||||
exit();
|
||||
}
|
||||
exit('Not authorized'.PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user