remove duplicated code
This commit is contained in:
parent
656e5fd052
commit
0f4ceedbb4
@ -54,10 +54,7 @@ function api_login(&$a){
|
|||||||
|
|
||||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||||
logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||||
header('WWW-Authenticate: Basic realm="Red"');
|
retry_basic_auth();
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
|
||||||
echo('This api requires login');
|
|
||||||
killme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process normal login request
|
// process normal login request
|
||||||
@ -80,10 +77,7 @@ function api_login(&$a){
|
|||||||
}
|
}
|
||||||
if(! $record) {
|
if(! $record) {
|
||||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||||
header('WWW-Authenticate: Basic realm="Red"');
|
retry_basic_auth();
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
|
||||||
echo('This api requires login');
|
|
||||||
killme();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,3 +89,11 @@ function api_login(&$a){
|
|||||||
|
|
||||||
$_SESSION['allow_api'] = true;
|
$_SESSION['allow_api'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function retry_basic_auth() {
|
||||||
|
header('WWW-Authenticate: Basic realm="Hubzilla"');
|
||||||
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
echo('This api requires login');
|
||||||
|
killme();
|
||||||
|
}
|
Reference in New Issue
Block a user