1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
/**
* Confirm the user's registration, and log the user
* @Rest\Route("/registration/confirm/{token}")
* @ApiDoc(
* section="Registration",
* resource=true,
* description="Confirm the user registration",
* requirements={
* {
* "name"="token",
* "dataType"="string",
* "description"="The user's confirmation token"
* }
* }
* )
*/
public function postConfirmAction($token)
{
//On met à jour l'utilisateur
$user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($token);
if (null === $user) {
throw new NotFoundHttpException('user_not_found');
}
$user->setConfirmationToken(null);
$user->setEnabled(true);
$this->get('fos_user.user_manager')->updateUser($user);
//on génère un access_token pour cet utilisateur (on le log automatiquement après sa confirmation)
$tokenManager = $this->get('fos_oauth_server.access_token_manager');
$oAuthServer = $this->get('fos_oauth_server.server');
$accessTokenClient = $tokenManager->findTokenByToken(
$this->get('security.context')->getToken()->getToken()
);
$client = $accessTokenClient->getClient();
$expiresIn = 14400;
$accessToken = $oAuthServer->createAccessToken($client, $user, null, $expiresIn);
return new Response(json_encode($accessToken), Codes::HTTP_OK, array(
'Content-Type' => 'application/json',
'Cache-Control' => 'no-store',
'Pragma' => 'no-cache',
));
} |
Partager