Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -55,17 +55,14 @@ private function unsubscribe(UserInterface $user, string $subscriptionHash)

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 = $user ?? new AnonymousUser();

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


namespace BenTools\WebPushBundle\Model\User;

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

/**
* This class is used to support anonymous user subscription
*
* @internal
*/
class AnonymousUser implements UserInterface
{
public function getRoles()
{
}

public function getPassword()
{
}

public function getSalt()
{
}

public function getUsername()
{
}

public function eraseCredentials()
{
}
}