当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getBodyAsString方法代码示例

本文整理汇总了PHP中Sabre\HTTP\Request::getBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getBodyAsString方法的具体用法?PHP Request::getBodyAsString怎么用?PHP Request::getBodyAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sabre\HTTP\Request的用法示例。


在下文中一共展示了Request::getBodyAsString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processPOST

 /**
  * Handle JMAP authentication requests (POST)
  */
 public function processPOST(Request $request, Response $response)
 {
     // decode JMAP request data
     $json_input = json_decode($request->getBodyAsString(), true);
     if ($json_input === null) {
         throw new ProcessorException(400, "Invalid JSON request body");
     }
     $response->setHeader('Content-Type', 'application/json');
     // initial auth request
     if (isset($json_input['username'])) {
         $this->ctrl->emit('jmap:auth:init', [['data' => $json_input, 'processor' => $this]]);
         $methods = [];
         foreach ($this->providers as $provider) {
             $methods = array_merge($methods, $provider->getAuthMethods());
         }
         // start session and generate the loginId
         $this->session->start();
         $this->session->set('Auth\\username', $json_input['username']);
         $result = ['methods' => array_unique($methods), 'loginId' => $this->session->key];
         // add prompt phrase stored in config
         if ($prompt = App::getInstance()->get('Config')->get('auth.prompt')) {
             $result['prompt'] = $prompt;
         }
         $status = 200;
         $this->ctrl->emit('jmap:auth:more', [['result' => &$result, 'status' => &$status, 'processor' => $this]]);
         $response->setBody(json_encode($result));
         $response->setStatus($status);
     } else {
         if (isset($json_input['loginId']) && isset($json_input['type'])) {
             $this->session->start($json_input['loginId']);
             // trigger event AFTER session has been initialized with the continuation token
             $this->ctrl->emit('jmap:auth:continue', [['data' => $json_input, 'processor' => $this]]);
             // validate token (which is the session key) ...
             if ($this->session->key !== $json_input['loginId'] || empty($this->session->get('Auth\\username'))) {
                 $this->ctrl->logger->debug("Invalid session loginId provided", ['input' => $json_input, 'session' => $this->session->key, 'username' => $this->session->get('Auth\\username')]);
                 $this->ctrl->emit('jmap:auth:restart', [['input' => $json_input, 'status' => 410, 'processor' => $this]]);
                 $response->setStatus(410);
                 // Restart authentication
                 return;
             }
             // ...and get username from session
             $json_input['username'] = $this->session->get('Auth\\username');
             $authenticated = false;
             foreach ($this->providers as $provider) {
                 if (self::getAuthMethod($provider, $json_input['type'])) {
                     try {
                         $authenticated = $provider->authenticate($json_input);
                     } catch (AuthenticationAbortedException $e) {
                         break;
                     }
                 }
                 if ($authenticated) {
                     break;
                 }
             }
             // authentication successful
             if ($authenticated && $authenticated instanceof AuthenticatedIdentity) {
                 $authenticated->username = $json_input['username'];
                 // replace session and generate the accessToken
                 $this->session->regenerateId(true);
                 $this->session->set('Auth\\authenticated', time());
                 $this->session->set('Auth\\identity', $authenticated);
                 // send success response
                 $this->sendAuthSuccess($response, $this->session->key);
             } else {
                 // report authentication failure
                 // TODO: create the same response as in initial auth request above
                 $this->ctrl->emit('jmap:auth:failure', [['input' => $json_input, 'status' => 403, 'processor' => $this]]);
                 $response->setStatus(403);
             }
         } else {
             $response->setStatus(401);
         }
     }
 }
开发者ID:roundcube-next,项目名称:roundcube-server,代码行数:78,代码来源:Auth.php


注:本文中的Sabre\HTTP\Request::getBodyAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。