本文整理汇总了PHP中DbHandler::isValidApiKey方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHandler::isValidApiKey方法的具体用法?PHP DbHandler::isValidApiKey怎么用?PHP DbHandler::isValidApiKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHandler
的用法示例。
在下文中一共展示了DbHandler::isValidApiKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Checking if the request has valid api key in the "Authorization" header
*/
function authenticate(\Slim\Route $route)
{
$headers = apache_request_headers();
$response = array();
$app = \Slim\Slim::getInstance();
if (isset($headers["Authorization"])) {
$db = new DbHandler();
$api_key = $headers["Authorization"];
$user = $db->isValidApiKey($api_key);
if ($user == null) {
$response["error"] = true;
$response["message"] = "Access Denied. Invalid Api key";
echoResponse(FAILURE_CODE, $response);
$app->stop();
} else {
global $user_name;
$user_name = $user;
}
} else {
$response["error"] = true;
$response["message"] = "Api key is misssing";
echoResponse(404, $response);
$app->stop();
}
}
示例2: authenticate
/**
* Adding Middle Layer to authenticate every request
* Checking if the request has valid api key in the 'Authorization' header
*/
function authenticate(\Slim\Route $route)
{
// Getting request headers
$headers = apache_request_headers();
$response = array();
$app = \Slim\Slim::getInstance();
// Verifying Authorization Header
if (isset($headers['Authorization'])) {
$db = new DbHandler();
// get the api key
$api_key = $headers['Authorization'];
// validating api key
if (!$db->isValidApiKey($api_key)) {
// api key is not present in users table
$response["error"] = true;
$response["message"] = "Access Denied. Invalid Api key";
echoRespnse(401, $response);
$app->stop();
} else {
global $user_id;
// get user primary key id
$user_id = $db->getUserId($api_key);
}
} else {
// api key is missing in header
$response["error"] = true;
$response["message"] = "Api key is misssing";
echoRespnse(400, $response);
$app->stop();
}
}
示例3: authenticate
/**
* Altenticação do usuário.
*
* @param \Slim\Route $route
*/
function authenticate(\Slim\Route $route)
{
// Getting request headers
$headers = apache_request_headers();
// Verifying Authorization Header
if (isset($headers['Authorization'])) {
$db = new DbHandler();
// get the api key
$apiKey = $headers['Authorization'];
// validating api key
if (!$db->isValidApiKey($apiKey)) {
// api key is not present in users table
$erro = MapaErro::singleton()->getErro(APIKEY_INVALIDA);
echoRespnse(HTTP_CONFLITO, $erro);
} else {
global $usuarioAutenticado;
// Recuperar usuário pelo ApiKey.
$usuario = $db->getUserByApiKey($apiKey);
if (!empty($usuario)) {
$usuarioAutenticado = $usuario;
}
}
} else {
// api key is missing in header
$erro = MapaErro::singleton()->getErro(NECESSARIO_LOGIN);
echoRespnse(HTTP_CONFLITO, $erro);
}
}