Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@
"chrome",
"firefox"
]
}
}
7 changes: 2 additions & 5 deletions src/Action/RegisterSubscriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace BenTools\WebPushBundle\Action;

use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerRegistry;
use BenTools\WebPushBundle\Model\User\AnonymousUser;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -49,17 +49,14 @@ private function unsubscribe(UserInterface $user, string $subscriptionHash): voi

public function __invoke(Request $request, UserInterface $user = null): Response
{
if (null === $user) {
throw new AccessDeniedHttpException('Not authenticated.');
}

if (!in_array($request->getMethod(), ['POST', 'DELETE'])) {
throw new MethodNotAllowedHttpException(['POST', 'DELETE']);
}

$data = json_decode($request->getContent(), true);
$subscription = $data['subscription'] ?? [];
$options = $data['options'] ?? [];
$user ??= new AnonymousUser();

if (JSON_ERROR_NONE !== json_last_error()) {
throw new BadRequestHttpException(json_last_error_msg());
Expand Down
38 changes: 38 additions & 0 deletions src/Model/User/AnonymousUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php


namespace BenTools\WebPushBundle\Model\User;

use Symfony\Component\Security\Core\User\UserInterface;

/**
* This class is used to support anonymous user subscription
*
* @internal
*/
final class AnonymousUser implements UserInterface
{
public function getRoles(): array
{
return [];
}

public function getPassword(): ?string
{
return null;
}

public function getSalt(): ?string
{
return null;
}

public function getUsername(): string
{
return '';
}

public function eraseCredentials(): void
{
}
}