Skip to content
Snippets Groups Projects
AuthController.php 3.17 KiB
Newer Older
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
<?php

namespace App\Controller;

use App\Service\Action\ActionServiceInterface;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use App\Service\Dto\Classes\ChangePasswordDto;
use App\Service\Dto\Classes\RecoveryDto;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use App\Service\Dto\Classes\RegisterCodeDto;
use App\Service\Dto\Classes\RegisterDto;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use App\Service\Dto\Classes\ResetPasswordCodeDto;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use App\Service\Response\Classes\Response;
use Nelmio\ApiDocBundle\Annotation\Model;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use Symfony\Component\DependencyInjection\Attribute\Autowire;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
use OpenApi\Attributes as OA;
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed

#[Route('/api', name: 'api_')]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
#[OA\Tag(name: 'Авторизация')]
#[OA\Response(
    response: 200,
    description: 'Ответ',
    content: new OA\JsonContent(
        ref: new Model(type: Response::class, groups: ["message"])
    )
)]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
class AuthController extends AbstractController
{
    #[Route('/register', name: 'register', methods: ['POST'])]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: RegisterDto::class))
    )]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    public function register(
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        #[Autowire(service: 'action.register')]
        ActionServiceInterface $actionService
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    ): JsonResponse
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();

    #[Route('/register/send', name: 'register_send', methods: ['GET'])]
    public function sendRegisterCode(
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        #[Autowire(service: 'action.register.send')]
        ActionServiceInterface $actionService,
    ): JsonResponse
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();
    }

    #[Route('/register/check', name: 'register_check', methods: ['POST'])]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: RegisterCodeDto::class))
    )]
    public function checkRegisterCode(
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        #[Autowire(service: 'action.register.code')]
        ActionServiceInterface $actionService
    ): JsonResponse
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed

    #[Route('/password/reset', name: 'password_reset', methods: ['POST'])]
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: ChangePasswordDto::class))
    )]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    public function resetPassword(
        #[Autowire(service: 'action.reset.password.change')]
        ActionServiceInterface $actionService
    ): JsonResponse
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    }

    #[Route('/password/send', name: 'password_send', methods: ['POST'])]
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: RecoveryDto::class))
    )]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    public function sendResetPassword(
        #[Autowire(service: 'action.reset.password.send')]
        ActionServiceInterface $actionService
    ): JsonResponse
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    }

    #[Route('/password/reset/check', name: 'password_reset_check', methods: ['POST'])]
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: ResetPasswordCodeDto::class))
    )]
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    public function resetCheckPassword(
        #[Autowire(service: 'action.reset.password.code')]
        ActionServiceInterface $actionService
    ): JsonResponse
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    {
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
        return $actionService->getResponse();
i.vasilenko@iq-adv.ru's avatar
i.vasilenko@iq-adv.ru committed
    }