/** * @param Request $request * @return JsonResponse|EmptyResponse */ public function handle(Request $request) { $actor = $request->getAttribute('actor'); $Referer = $request->getHeader('Referer'); $params = array_only($request->getParsedBody(), ['identification', 'password']); $response = $this->apiClient->send(TokenController::class, $actor, [], $params); if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()); $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $data->userId); $token = AccessToken::find($data->token); event(new UserLoggedIn($this->users->findOrFail($data->userId), $token)); $response = FigResponseCookies::set($response, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/')); $response = $this->rememberer->remember($response, $token); } elseif ($response->getStatusCode() === 401) { $responseNew = $this->apiClient->send(PingxxTokenController::class, $actor, [], $params); if ($responseNew->getStatusCode() === 200) { $data = json_decode($responseNew->getBody()); $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $data->userId); $token = AccessToken::find($data->token); event(new UserLoggedIn($this->users->findOrFail($data->userId), $token)); $responseNew = FigResponseCookies::set($responseNew, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/')->withDomain('dashboard.pingxx.com')); $responseNew = $this->rememberer->remember($responseNew, $token); return $responseNew; } else { return $response; } } return $response; }
/** * @param Request $request * @return JsonResponse|EmptyResponse */ public function handle(Request $request) { $actor = $request->getAttribute('actor'); $params = array_only($request->getParsedBody(), ['identification', 'password']); $response = $this->apiClient->send(TokenController::class, $actor, [], $params); if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()); $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $data->userId); $token = AccessToken::find($data->token); event(new UserLoggedIn($this->users->findOrFail($data->userId), $token)); $response = $this->rememberer->remember($response, $token); } return $response; }
/** * @param Request $request * @return JsonResponse */ public function handle(Request $request) { $controller = 'Flarum\\Api\\Controller\\CreateUserController'; $actor = $request->getAttribute('actor'); $body = ['data' => ['attributes' => $request->getParsedBody()]]; $response = $this->api->send($controller, $actor, [], $body); $body = json_decode($response->getBody()); if (isset($body->data)) { $userId = $body->data->id; $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $userId); $response = $this->rememberer->rememberUser($response, $userId); } return $response; }
/** * @param Request $request * @param array $routeParams * * @return JsonResponse */ public function handle(Request $request, array $routeParams = []) { $params = ['data' => ['attributes' => $request->getAttributes()]]; $apiResponse = $this->apiClient->send(app('flarum.actor'), 'Flarum\\Api\\Actions\\Users\\CreateAction', $params); $body = $apiResponse->getBody(); $statusCode = $apiResponse->getStatusCode(); $response = new JsonResponse($body, $statusCode); if (!empty($body->data->attributes->isActivated)) { $token = $this->bus->dispatch(new GenerateAccessToken($body->data->id)); // Extend the token's expiry to 2 weeks so that we can set a // remember cookie AccessToken::where('id', $token->id)->update(['expires_at' => new DateTime('+2 weeks')]); return $this->withRememberCookie($response, $token->id); } return $response; }
/** * @param Request $request * @param array $routeParams * @return JsonResponse|EmptyResponse */ public function handle(Request $request, array $routeParams = []) { $params = array_only($request->getAttributes(), ['identification', 'password']); $data = $this->apiClient->send(app('flarum.actor'), 'Flarum\\Api\\Actions\\TokenAction', $params)->getBody(); // TODO: The client needs to pass through exceptions(?) or the whole // response so we can look at the response code. For now if there isn't // any useful data we just assume it's a 401. if (isset($data->userId)) { // Extend the token's expiry to 2 weeks so that we can set a // remember cookie AccessToken::where('id', $data->token)->update(['expires_at' => new DateTime('+2 weeks')]); event(new UserLoggedIn($this->users->findOrFail($data->userId), $data->token)); return $this->withRememberCookie(new JsonResponse($data), $data->token); } else { return new EmptyResponse(401); } }
/** * @param Request $request * @param array $routeParams * @return JsonResponse|EmptyResponse */ public function handle(Request $request, array $routeParams = []) { $controller = 'Flarum\\Api\\Controller\\TokenController'; $actor = $request->getAttribute('actor'); $params = array_only($request->getParsedBody(), ['identification', 'password']); $response = $this->apiClient->send($controller, $actor, [], $params); if ($response->getStatusCode() === 200) { $data = json_decode($response->getBody()); // Extend the token's expiry to 2 weeks so that we can set a // remember cookie AccessToken::where('id', $data->token)->update(['expires_at' => new DateTime('+2 weeks')]); event(new UserLoggedIn($this->users->findOrFail($data->userId), $data->token)); return $this->withRememberCookie($response, $data->token); } else { return $response; } }
/** * Get the result of an API request to show the current user. * * @return object */ protected function getUserDocument() { // TODO: calling on the API here results in an extra query to get // the user + their groups, when we already have this information on // $this->actor. Can we simply run the CurrentUserSerializer // manually? Or can we somehow inject this data into the ShowDiscussionController? $document = json_decode($this->api->send('Flarum\\Api\\Controller\\ShowUserController', $this->actor, ['id' => $this->actor->id])->getBody()); return $document; }
/** * Get the result of an API request to show the current user. * * @return object */ protected function getUserDocument() { // TODO: calling on the API here results in an extra query to get // the user + their groups, when we already have this information on // $this->actor. Can we simply run the CurrentUserSerializer // manually? Or can we somehow inject this data into the ShowAction? $document = $this->apiClient->send($this->actor, 'Flarum\\Api\\Actions\\Users\\ShowAction', ['id' => $this->actor->id])->getBody(); return $document; }
/** * @param Request $request * @param array $routeParams * * @return JsonResponse */ public function handle(Request $request, array $routeParams = []) { $controller = 'Flarum\\Api\\Controller\\CreateUserController'; $actor = $request->getAttribute('actor'); $body = ['data' => ['attributes' => $request->getParsedBody()]]; $response = $this->api->send($controller, $actor, [], $body); $body = json_decode($response->getBody()); $statusCode = $response->getStatusCode(); $response = new JsonResponse($body, $statusCode); if (!empty($body->data->attributes->isActivated)) { $token = $this->bus->dispatch(new GenerateAccessToken($body->data->id)); // Extend the token's expiry to 2 weeks so that we can set a // remember cookie AccessToken::where('id', $token->id)->update(['expires_at' => new DateTime('+2 weeks')]); return $this->withRememberCookie($response, $token->id); } return $response; }
/** * Get the result of an API request to list discussions. * * @param User $actor * @param array $params * @return object */ private function getDocument(User $actor, array $params) { return json_decode($this->api->send('Flarum\\Api\\Controller\\ListDiscussionsController', $actor, $params)->getBody()); }
/** * Get the result of an API request to show the forum. * * @return array */ protected function getForumDocument(Request $request) { $actor = $request->getAttribute('actor'); $response = $this->api->send('Flarum\\Api\\Controller\\ShowForumController', $actor); return json_decode($response->getBody(), true); }