Example #1
0
 /**
  * Get the user results, ready to be serialized and assigned to the
  * document response.
  *
  * @param JsonApiRequest $request
  * @param Document $document
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function data(JsonApiRequest $request, Document $document)
 {
     $criteria = new SearchCriteria($request->actor, $request->get('filter.q'), $request->sort);
     $results = $this->searcher->search($criteria, $request->limit, $request->offset, $request->include);
     $this->addPaginationLinks($document, $request, $this->url->toRoute('flarum.api.users.index'), $results->areMoreResults());
     return $results->getResults();
 }
Example #2
0
 /**
  * Get the discussion results, ready to be serialized and assigned to the
  * document response.
  *
  * @param JsonApiRequest $request
  * @param Document $document
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function data(JsonApiRequest $request, Document $document)
 {
     $criteria = new SearchCriteria($request->actor, $request->get('filter.q'), $request->sort);
     $load = array_merge($request->include, ['state']);
     $results = $this->searcher->search($criteria, $request->limit, $request->offset, $load);
     // TODO: add query params (filter, sort, include) to the pagination URLs
     $this->addPaginationLinks($document, $request, $request->http ? $this->url->toRoute('flarum.api.discussions.index') : '', $results->areMoreResults());
     return $results->getResults();
 }
Example #3
0
 /**
  * @param Request $request
  * @param array $routeParams
  * @return RedirectResponse|EmptyResponse
  */
 public function handle(Request $request, array $routeParams = [])
 {
     session_start();
     $provider = new Github(['clientId' => $this->settings->get('github.client_id'), 'clientSecret' => $this->settings->get('github.client_secret'), 'redirectUri' => $this->url->toRoute('github.login')]);
     if (!isset($_GET['code'])) {
         $authUrl = $provider->getAuthorizationUrl(['scope' => ['user:email']]);
         $_SESSION['oauth2state'] = $provider->getState();
         return new RedirectResponse($authUrl);
     } elseif (empty($_GET['state']) || $_GET['state'] !== $_SESSION['oauth2state']) {
         unset($_SESSION['oauth2state']);
         echo 'Invalid state.';
         exit;
     }
     $token = $provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
     $owner = $provider->getResourceOwner($token);
     $email = $owner->getEmail();
     $username = preg_replace('/[^a-z0-9-_]/i', '', $owner->getNickname());
     return $this->authenticated(compact('email'), compact('username'));
 }