Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Gigadrive
qpost
qpost
Commits
5444ac18
Verified
Commit
5444ac18
authored
Aug 24, 2020
by
Mehdi Baaboura
Browse files
Updated TokenService
parent
440b6801
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
14 deletions
+21
-14
src/Controller/API/APIController.php
src/Controller/API/APIController.php
+4
-2
src/Controller/API/TokenController.php
src/Controller/API/TokenController.php
+1
-1
src/Controller/qpostController.php
src/Controller/qpostController.php
+9
-1
src/Service/TokenService.php
src/Service/TokenService.php
+7
-10
No files found.
src/Controller/API/APIController.php
View file @
5444ac18
...
...
@@ -41,6 +41,7 @@ use qpost\Exception\ResourceNotFoundException;
use
qpost\Service\APIService
;
use
qpost\Service\DataDeletionService
;
use
qpost\Service\StorageService
;
use
qpost\Service\TokenService
;
use
qpost\Service\TranslationService
;
use
Symfony\Component\HttpFoundation\ParameterBag
;
use
Symfony\Component\HttpFoundation\Request
;
...
...
@@ -76,9 +77,10 @@ class APIController extends qpostController {
EntityManagerInterface
$entityManager
,
LoggerInterface
$logger
,
DataDeletionService
$dataDeletionService
,
StorageService
$storageService
StorageService
$storageService
,
TokenService
$tokenService
)
{
parent
::
__construct
(
$generalService
,
$paginationService
,
$translationService
);
parent
::
__construct
(
$generalService
,
$paginationService
,
$translationService
,
$tokenService
);
$this
->
apiService
=
$apiService
;
$this
->
entityManager
=
$entityManager
;
...
...
src/Controller/API/TokenController.php
View file @
5444ac18
...
...
@@ -90,7 +90,7 @@ class TokenController extends APIController {
*/
public
function
verify
()
{
$this
->
validateAuth
();
$token
=
$this
->
api
Service
->
getToken
();
$token
=
$this
->
token
Service
->
get
Current
Token
();
$user
=
$token
->
getUser
();
if
(
!
$user
->
isSuspended
())
{
...
...
src/Controller/qpostController.php
View file @
5444ac18
...
...
@@ -23,6 +23,7 @@ namespace qpost\Controller;
use
Gigadrive\Bundle\SymfonyExtensionsBundle\Controller\GigadriveController
;
use
Gigadrive\Bundle\SymfonyExtensionsBundle\Service\Database\Pagination\PaginationService
;
use
Gigadrive\Bundle\SymfonyExtensionsBundle\Service\GigadriveGeneralService
;
use
qpost\Service\TokenService
;
use
qpost\Service\TranslationService
;
class
qpostController
extends
GigadriveController
{
...
...
@@ -31,13 +32,20 @@ class qpostController extends GigadriveController {
*/
protected
$i18n
;
/**
* @var TokenService $tokenService
*/
protected
$tokenService
;
public
function
__construct
(
GigadriveGeneralService
$generalService
,
PaginationService
$pagination
,
TranslationService
$i18n
TranslationService
$i18n
,
TokenService
$tokenService
)
{
parent
::
__construct
(
$generalService
,
$pagination
);
$this
->
i18n
=
$i18n
;
$this
->
tokenService
=
$tokenService
;
}
}
\ No newline at end of file
src/Service/TokenService.php
View file @
5444ac18
<?php
/*
*
/*
* Copyright (C) 2018-2020 Gigadrive - All rights reserved.
* https://gigadrivegroup.com
* https://qpostapp.com
...
...
@@ -23,7 +23,6 @@ namespace qpost\Service;
use
DateInterval
;
use
DateTime
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Gigadrive\Bundle\SymfonyExtensionsBundle\DependencyInjection\Util
;
use
Psr\Log\LoggerInterface
;
use
qpost\Entity\Token
;
use
Symfony\Component\HttpFoundation\Cookie
;
...
...
@@ -70,16 +69,14 @@ class TokenService {
public
function
getTokenFromRequest
(
Request
$request
):
?Token
{
$token
=
null
;
if
((
Util
::
startsWith
(
$request
->
getPathInfo
(),
"/api"
)
||
Util
::
startsWith
(
$request
->
getPathInfo
(),
"/webpush"
))
&&
$request
->
headers
->
has
(
"Authorization"
))
{
$authorization
=
$request
->
headers
->
get
(
"Authorization"
);
$authorizationHeader
=
$request
->
headers
->
get
(
"Authorization"
);
if
(
$authorization
&&
is_string
(
$authorization
))
{
$prefix
=
"Bearer "
;
if
(
$authorization
Header
&&
is_string
(
$authorization
Header
))
{
$prefix
=
"Bearer "
;
// Check if starts with token type prefix
if
(
strlen
(
$authorization
)
>
strlen
(
$prefix
)
&&
substr
(
$authorization
,
0
,
strlen
(
$prefix
))
===
$prefix
)
{
$token
=
substr
(
$authorization
,
strlen
(
$prefix
));
}
// Check if starts with token type prefix
if
(
strlen
(
$authorizationHeader
)
>
strlen
(
$prefix
)
&&
substr
(
$authorizationHeader
,
0
,
strlen
(
$prefix
))
===
$prefix
)
{
$token
=
substr
(
$authorizationHeader
,
strlen
(
$prefix
));
}
}
else
if
(
$request
->
cookies
->
has
(
self
::
TOKEN_COOKIE_IDENTIFIER
))
{
$cookieTokens
=
$this
->
getCookieTokens
(
$request
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment