|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Api; |
|
4
|
|
|
|
|
5
|
|
|
use App\Document\Provider; |
|
6
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
|
7
|
|
|
use Nelmio\ApiDocBundle\Annotation\Model; |
|
8
|
|
|
use Nelmio\ApiDocBundle\Annotation\Security; |
|
9
|
|
|
use Swagger\Annotations as SWG; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Provide routes for Profile API. |
|
16
|
|
|
* |
|
17
|
|
|
* @Route("/api/me", name="api_profile_", defaults={"_format": "json"}) |
|
18
|
|
|
*/ |
|
19
|
|
|
class ProfileController extends AbstractController |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Profile. |
|
23
|
|
|
* |
|
24
|
|
|
* @Route("", name="me", methods={"GET"}) |
|
25
|
|
|
* @SWG\Response( |
|
26
|
|
|
* response=200, |
|
27
|
|
|
* description="Returns my profile", |
|
28
|
|
|
* @SWG\Schema(@SWG\Items(ref=@Model(type=Provider::class, groups={"user_profile", "token_default"}))) |
|
29
|
|
|
* ) |
|
30
|
|
|
* @SWG\Tag(name="profile") |
|
31
|
|
|
* @Security(name="Bearer") |
|
32
|
|
|
*/ |
|
33
|
|
|
public function me(): Response |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->json($this->getUser(), Response::HTTP_OK, [], ['groups' => ['user_profile', 'token_default']]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Regenerate personal key. |
|
40
|
|
|
* |
|
41
|
|
|
* @Route("/regenerate-token", name="regenerate_token", methods={"POST"}) |
|
42
|
|
|
* @SWG\Response( |
|
43
|
|
|
* response=201, |
|
44
|
|
|
* description="Regenerate personal key", |
|
45
|
|
|
* ) |
|
46
|
|
|
* @SWG\Tag(name="profile") |
|
47
|
|
|
* @Security(name="Bearer") |
|
48
|
|
|
*/ |
|
49
|
|
|
public function regenerateToken(DocumentManager $dm): Response |
|
50
|
|
|
{ |
|
51
|
|
|
$this->getUser()->generateToken(); |
|
52
|
|
|
$dm->flush(); |
|
53
|
|
|
|
|
54
|
|
|
return new Response('', Response::HTTP_CREATED); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|