當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DbHandler::isValidApiKey方法代碼示例

本文整理匯總了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();
    }
}
開發者ID:sharathvignesh,項目名稱:Tamil-Readers-Association,代碼行數:28,代碼來源:index.php

示例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();
    }
}
開發者ID:stephaneGJ,項目名稱:my_contacts_api,代碼行數:35,代碼來源:index.php

示例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);
    }
}
開發者ID:joseilsonjunior,項目名稱:nutrif,代碼行數:33,代碼來源:index.php


注:本文中的DbHandler::isValidApiKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。