-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSessionCheckController.php
More file actions
85 lines (79 loc) · 2.81 KB
/
Copy pathSessionCheckController.php
File metadata and controls
85 lines (79 loc) · 2.81 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Rest\Server\Controller\Session;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model;
use Ibexa\Rest\Server\Values\UserSession;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
#[Get(
uriTemplate: '/user/sessions/current',
openapi: new Model\Operation(
operationId: 'ibexa.rest.check_session',
summary: 'Get current session',
description: 'Get current user session, if any.',
tags: [
'User Session',
],
parameters: [
new Model\Parameter(
name: 'Cookie',
in: 'header',
required: false,
description: 'Only needed for session\'s checking {sessionName}={sessionID}.',
schema: [
'type' => 'string',
],
),
],
responses: [
Response::HTTP_OK => [
'description' => 'User is currently logged in and has a valid session.',
'content' => [
'application/vnd.ibexa.api.Session+json' => [
'schema' => [
'$ref' => '#/components/schemas/SessionWrapper',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/sessions/session_id/refresh/POST/Session.json.example',
],
'application/vnd.ibexa.api.Session+xml' => [
'schema' => [
'$ref' => '#/components/schemas/Session',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/sessions/POST/Session.xml.example',
],
],
],
Response::HTTP_NOT_FOUND => [
'description' => 'User does not have a valid session, or it has expired.',
],
],
),
)]
/**
* @internal
*/
final class SessionCheckController extends SessionBaseController
{
public function checkSessionAction(Request $request): Response|UserSession
{
$session = $request->getSession();
if (!$session->isStarted()) {
return $this->logout($request);
}
$currentUser = $this->userService->loadUser(
$this->permissionResolver->getCurrentUserReference()->getUserId()
);
return new UserSession(
$currentUser,
$session->getName(),
$session->getId(),
$this->getCsrfToken(),
false
);
}
}