/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $body = $request->getParsedBody(); $identification = array_get($body, 'identification'); $password = array_get($body, 'password'); $user = $this->users->findByIdentification($identification); if (!$user || !$user->checkPassword($password)) { throw new PermissionDeniedException(); } $token = AccessToken::generate($user->id); $token->save(); return new JsonResponse(['token' => $token->id, 'userId' => $user->id]); }
/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $body = $request->getParsedBody(); $identification = array_get($body, 'identification'); $password = array_get($body, 'password'); $user = $this->users->findByIdentification($identification); if (!$user || !$user->checkPassword($password)) { throw new PermissionDeniedException(); } if (!$user->is_activated) { $this->events->fire(new UserEmailChangeWasRequested($user, $user->email)); return new JsonResponse(['emailConfirmationRequired' => $user->email], 401); } $token = $this->bus->dispatch(new GenerateAccessToken($user->id)); return new JsonResponse(['token' => $token->id, 'userId' => $user->id]); }