Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Created January 9, 2013 11:47
Show Gist options
  • Save sveneisenschmidt/4492564 to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/4492564 to your computer and use it in GitHub Desktop.
<?php
// ...
class UserController extends AbstractApiController
{
/**
*
* @Rest\View()
* @Rest\QueryParam(name="_token", description="The token for authentication.")
* @ApiDoc(
* resource=true,
* description="Gets User associated to id. Needs Authentication.",
* statusCodes={
* 200="Returned when successful",
* 400="Returned when the token is invalid.",
* 403="Returned when the enquirer is not authorized."
* },
* filters={
* {"name"="_format", "dataType"="string", "pattern"="(json|xml)"}
* }
* )
*/
public function getUserAction(ParamFetcherInterface $paramFetcher, $id)
{
$manager = $this->getDoctrine()->getManager();
$repository = $manager->getRepository('WildlyCoreBundle:User');
if(null === ($token = $paramFetcher->get('_token'))) {
throw new HttpException(400, 'Missing authentication token.');
}
if(null === ($enquirer = $repository->findOneByApiToken($token))) {
throw new HttpException(400, 'Invalid authentication token.');
}
if(false === $enquirer->getIsActive()) {
throw new HttpException(403, 'Forbidden. User with request token is disabled.');
}
// @todo load user
$user = null;
return $user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment