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


PHP User::getUserByPublicKey方法代碼示例

本文整理匯總了PHP中models\User::getUserByPublicKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::getUserByPublicKey方法的具體用法?PHP User::getUserByPublicKey怎麽用?PHP User::getUserByPublicKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models\User的用法示例。


在下文中一共展示了User::getUserByPublicKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: authenticate

 /**
  * This is the authenticate method where we check the X-Hash header from the client against
  * a hash that we will recreate here on the server. If the 2 match, it's a pass.
  *
  * @param String $public_key
  * @return boolean If success or not
  */
 public function authenticate($public_key)
 {
     //get request and X-Hash HTTP header
     $request = $this->app->request();
     $contentHash = $request->headers('X-Hash');
     $oUser = new User();
     $user = $oUser->getUserByPublicKey($public_key);
     //get private key for hashing
     $private_key = $oUser->getPrivateKey($user['LoginID']);
     //get HTTP request body for hashing
     $requestBody = $request->getBody();
     //hash the body and clientside timestamp and our private key from the user
     $hash = hash_hmac('sha256', $requestBody, $private_key);
     //if they match, the request is valid.
     if (md5($contentHash) === md5($hash)) {
         Log::write("authenticated for " . strtoupper($request->getMethod()) . "/" . $request->getPath(), $user['username']);
         return TRUE;
     } else {
         Log::write("Hashes do not match.", $user['username']);
         Log::write("Clienthash: " . $contentHash, $user['username']);
         Log::write("Serverhash: " . $hash, $user['username']);
         return FALSE;
     }
 }
開發者ID:Rudianasaja,項目名稱:openMEDIS-Slim-PHP-REST-API,代碼行數:31,代碼來源:AuthMiddleware.php

示例2: function

use lib\RequestHelper as R;
use lib\LogHelper as Log;
// API Versioning
$app->group('/v1', function () use($app) {
    /**
     * GET route to export whole database to JSON
     *
     */
    $app->get('/database/export', function () use($app) {
        //create empty user
        $oUser = new User();
        //request header
        $request = $app->request();
        $public_key = $request->headers('X-PublicKey');
        //get User array from sent public key
        $user = $oUser->getUserByPublicKey($public_key);
        $userdb = $oUser->setDefaultDatabase($user['LoginID']);
        //get access level string of user
        $access_level = $oUser->getAccessLevel($user['LoginID']);
        //create new instance with the user specific database
        $tempTool = new DbExport($userdb);
        //read relevant table names with the user specific access level
        $export = $tempTool->readRelevantTables($access_level);
        $app->contentType('application/json;charset=utf-8');
        echo json_encode($export);
    });
    /**
     * GET route to export database meta information to JSON
     *
     */
    $app->get('/database/scheme', function () use($app) {
開發者ID:Rudianasaja,項目名稱:openMEDIS-Slim-PHP-REST-API,代碼行數:31,代碼來源:dbexport.router.php

示例3: readUsernameFromRequest

 /**
  * Read the user belonging to the incoming request and get his/her defaultDB.
  *
  * @return String $userdb
  */
 public static function readUsernameFromRequest()
 {
     $app = \Slim\Slim::getInstance();
     $oUser = new User();
     $request = $app->request();
     $public_key = $request->headers('X-PublicKey');
     //get User array from sent public key
     $user = $oUser->getUserByPublicKey($public_key);
     $username = $user['username'];
     if ($username != NULL) {
         return $username;
     } else {
         return false;
     }
 }
開發者ID:Rudianasaja,項目名稱:openMEDIS-Slim-PHP-REST-API,代碼行數:20,代碼來源:RequestHelper.php


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