当前位置: 首页>>代码示例>>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;未经允许,请勿转载。