43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
|
<?php
|
||
|
require(__DIR__."/dbOperations.inc.php");
|
||
|
|
||
|
class Authenticator {
|
||
|
function isApiKeyAuthenticated($key) {
|
||
|
$db = new DbOperations();
|
||
|
$db->select("api_keys", array("quota_max", "client_key"));
|
||
|
$db->where("client_key", Comparison::EQUAL, $key);
|
||
|
|
||
|
$result = $db->execute();
|
||
|
|
||
|
if (count($result) == 1 && $result[0]['quota_max'] > 0)
|
||
|
return true;
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
function isSessionAuthenticated($session) {
|
||
|
if (isset($session['stayloggedin'])) {
|
||
|
if($session["stayloggedin"]) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!isset($session['until'])) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if ($session['until'] > time() || $session['until'] == 0)
|
||
|
return true;
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
function isAuthenticated($session, $request) {
|
||
|
if (isset($request['key'])) {
|
||
|
return $this->isApiKeyAuthenticated($request['key']);
|
||
|
} else {
|
||
|
return $this->isSessionAuthenticated($session);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|