Skip to content

Commit

Permalink
fixed #31 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
algirdasc committed May 7, 2024
1 parent a23ba6b commit c29200e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"symfony/rate-limiter": "7.0.*",
"symfony/runtime": "7.0.*",
"symfony/security-bundle": "7.0.*",
"symfony/serializer": "~7.0.7@dev",
"symfony/serializer": "7.0.*",
"symfony/validator": "7.0.*",
"symfony/yaml": "7.0.*"
},
Expand Down
4 changes: 0 additions & 4 deletions backend/src/Controller/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
use App\Controller\AbstractApiController;
use App\Enum\ErrorEnum;
use LogicException;
use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

#[Route('api/auth/login', name: 'login_')]
#[OA\Tag(name: 'Authentication')]
#[Security(name: '')]
class LoginController extends AbstractApiController
{
#[Route('', name: 'index', methods: Request::METHOD_POST)]
Expand Down
2 changes: 0 additions & 2 deletions backend/src/Controller/Auth/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use App\Controller\AbstractApiController;
use App\Response\EmptyResponse;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

#[Route('api/auth/logout', name: 'logout_')]
#[OA\Tag(name: 'Authentication')]
class LogoutController extends AbstractApiController
{
#[Route('', name: 'index', methods: Request::METHOD_DELETE)]
Expand Down
4 changes: 0 additions & 4 deletions backend/src/Controller/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
use App\Request\Auth\PasswordResetRequest;
use App\Response\EmptyResponse;
use App\Service\PasswordResetService;
use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

#[Route('api/auth/password', name: 'password_')]
#[OA\Tag(name: 'Authentication')]
#[Security(name: '')]
class PasswordController extends AbstractApiController
{
#[Route('/forgot', name: 'forgot', methods: Request::METHOD_POST)]
Expand Down
24 changes: 16 additions & 8 deletions backend/src/Controller/Auth/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@
use App\Controller\AbstractApiController;
use App\Entity\Calendar;
use App\Entity\User;
use App\Repository\CalendarRepository;
use App\Repository\UserRepository;
use App\Request\Auth\RegistrationRequest;
use App\Response\Auth\AuthTokenResponse;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

#[Route('api/auth/register', name: 'registration_')]
#[OA\Tag(name: 'Authentication')]
#[Security(name: '')]
class RegistrationController extends AbstractApiController
{
public function __construct(
private readonly CalendarRepository $calendarRepository,
private readonly UserRepository $userRepository,
) {
}

#[Route('', name: 'create', methods: Request::METHOD_POST)]
public function index(RegistrationRequest $request, JWTTokenManagerInterface $JWTManager, UserRepository $userRepository): JsonResponse
public function index(RegistrationRequest $request, JWTTokenManagerInterface $JWTManager): JsonResponse
{
$user = (new User())
->setEmail($request->getEmail())
Expand All @@ -32,10 +35,15 @@ public function index(RegistrationRequest $request, JWTTokenManagerInterface $JW
->setPlainPassword($request->getPassword())
;

new Calendar('Personal', $user);
$calendar = new Calendar('Personal', $user);

$userRepository->save($user);
$this->userRepository->save($user);
$this->calendarRepository->save($calendar);

return $this->respond(new AuthTokenResponse($JWTManager->create($user)));
return $this->respond(
new AuthTokenResponse(
$JWTManager->create($user)
)
);
}
}

0 comments on commit c29200e

Please sign in to comment.