Skip to content
Merged
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker/pgdata
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###> symfony/mailer ###
MAILER_DSN=null://null
###< symfony/mailer ###

# Настройки Xdebug
XDEBUG_CLIENT_HOST=host.docker.internal
XDEBUG_IDEKEY=PHPSTORM
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ phpstan.neon
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> IDE files ###
/docker/pgdata
/docker/.env
###> IDE files ###
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ install:
validate:
composer validate

PORT ?= 8000
start:
symfony server:start
#php -S localhost:8000 -t public/
#PHP_CLI_SERVER_WORKERS=5 php -S 0.0.0.0:$(PORT) -t public

lint: phpcsfixer-check phpstan

Expand All @@ -27,4 +28,13 @@ phpstan-baseline:
test:
./bin/phpunit

docker-up-d:
docker-compose --env-file ./docker/.env up -d

docker-down:
docker-compose --env-file ./docker/.env down -v

docker-build:
docker-compose --env-file ./docker/.env build

.PHONY: tests
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@

### Run tests
> `make test`

### API requests
> Запрос кода подтверждения
>
> POST
>
> http://127.0.0.1:8000/api/user/request-code
>
> ```json
> {
> "phone_number": "+79157053551"
> }
> ```

> Проверка кода подтверждения
>
> POST
>
> http://127.0.0.1:8000/api/verify-code
>
> ```json
> {
> "phone_number": "+79157053551",
> "phone_code": "1234"
> }
> ```
18 changes: 0 additions & 18 deletions compose.override.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions compose.yaml

This file was deleted.

68 changes: 68 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: '3.8'

services:
ilyaguev_igor-indigolab-php:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: ilyaguev_igor-indigolab-php
volumes:
- ./:/var/www/html
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@ilyaguev_igor-indigolab-postgres:5432/${POSTGRES_DB}
- REDIS_URL=redis://ilyaguev_igor-indigolab-redis:6379
# - XDEBUG_CLIENT_HOST=${XDEBUG_CLIENT_HOST}
# - XDEBUG_IDEKEY=${XDEBUG_IDEKEY}
depends_on:
- ilyaguev_igor-indigolab-postgres
- ilyaguev_igor-indigolab-redis
networks:
- indigolab-network


ilyaguev_igor-indigolab-nginx:
image: nginx:latest
container_name: ilyaguev_igor-indigolab-nginx
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./docker/nginx/conf.d:/etc/nginx/conf.d
- ./public:/var/www/html/public
depends_on:
- ilyaguev_igor-indigolab-php
networks:
- indigolab-network

ilyaguev_igor-indigolab-postgres:
image: postgres:latest
container_name: ilyaguev_igor-indigolab-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_ROOT_PASSWORD: ${POSTGRES_ROOT_PASSWORD}
TZ: "Europe/Moscow"
ports:
- "${POSTGRES_PORT}:5432"
volumes:
- ./docker/pgdata:/var/lib/postgresql/data
networks:
- indigolab-network

ilyaguev_igor-indigolab-redis:
image: redis:latest
container_name: ilyaguev_igor-indigolab-redis
restart: unless-stopped
ports:
- "6379:6379"
networks:
- indigolab-network

volumes:
postgres_data:

networks:
indigolab-network:
driver: bridge
5 changes: 5 additions & 0 deletions docker/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_DB=indigolab
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=postgres_password
POSTGRES_ROOT_PASSWORD=postgres_root_password
POSTGRES_PORT=5432
27 changes: 27 additions & 0 deletions docker/nginx/conf.d/conf.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
listen 80;
server_name localhost;

root /var/www/html/public;
index index.php;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
fastcgi_pass ilyaguev_igor-indigolab-php:9000; # Связь с PHP-FPM
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
internal;
}

location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
44 changes: 44 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM php:8.3-fpm

# Устанавливаем необходимые зависимости
RUN apt-get update && apt-get install -y \
git \
libzip-dev \
libpq-dev \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Устанавливаем расширения PHP
RUN docker-php-ext-install zip pdo pdo_pgsql opcache

# Настройка PHP
COPY docker/php/php.ini /usr/local/etc/php/conf.d/

# Устанавливаем Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"

# Устанавливаем Xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug

# Копируем конфигурацию Xdebug
#COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

# Устанавливаем рабочую директорию
WORKDIR /var/www/html

# Копируем только файлы, необходимые для установки зависимостей
COPY composer.json composer.lock symfony.lock ./

# Устанавливаем зависимости Composer
RUN composer install

# Копируем весь исходный код
COPY . .

# Указываем пользователя для выполнения команд
USER www-data

# Права для веб-сервера
RUN chown -R www-data:www-data /var/www/html/var
4 changes: 4 additions & 0 deletions docker/php/conf.d/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.client_host=${XDEBUG_CLIENT_HOST}
xdebug.idekey=${XDEBUG_IDEKEY}
Empty file added docker/php/php.ini
Empty file.
37 changes: 20 additions & 17 deletions src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace App\Controller;

use App\Dto\Request\GetPhoneCodeDto;
use App\Dto\Request\RequestPhoneCodeDto;
use App\Dto\Request\VerifyPhoneCodeDto;
use App\Service\PhoneVerificationService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -15,30 +16,32 @@ final class UserController extends AbstractController
* @throws \Exception
*/
#[Route(
'/user/request-code',
name: 'user_request_code',
'/request-code',
name: 'request_code',
methods: ['POST'])
]
public function requestCode(
#[MapRequestPayload] GetPhoneCodeDto $requestDto,
#[MapRequestPayload] RequestPhoneCodeDto $requestDto,
PhoneVerificationService $verificationService,
): JsonResponse {
$phoneCodeDto = $verificationService->getPhoneCode($requestDto);

return $this->json($phoneCodeDto);
}

// #[Route('/verify-code', methods: ['POST'])]
// public function verifyCode(Request $request): JsonResponse
// {
// $phoneNumber = $request->request->get('phone_number');
// $code = $request->request->get('code');
//
// try {
// $user = $this->verificationService->verifyCode($phoneNumber, $code);
// return $this->json(['success' => true, 'user_id' => $user->getId()]);
// } catch (\Exception $e) {
// return $this->json(['error' => $e->getMessage()], 400);
// }
// }
/**
* @throws \Exception
*/
#[Route('/verify-code', methods: ['POST'])]
public function verifyCode(
#[MapRequestPayload] VerifyPhoneCodeDto $requestDto,
PhoneVerificationService $verificationService,
): JsonResponse {
$authDto = $verificationService->verifyCode(
$requestDto->getPhoneNumber(),
$requestDto->getPhoneCode()
);

return $this->json($authDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Symfony\Component\Validator\Constraints as Assert;

class GetPhoneCodeDto
class RequestPhoneCodeDto
{
#[Assert\NotBlank(message: 'Phone number cannot be blank.')]
#[Assert\NotBlank(message: 'Phone number cannot be blank')]
#[Assert\Regex(
pattern: '/^\+79\d{9}$/',
message: 'Phone number must be in the format +79151234567'
Expand Down
44 changes: 44 additions & 0 deletions src/Dto/Request/VerifyPhoneCodeDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Dto\Request;

use Symfony\Component\Validator\Constraints as Assert;

class VerifyPhoneCodeDto
{
#[Assert\NotBlank(message: 'Phone number cannot be blank')]
#[Assert\Regex(
pattern: '/^\+79\d{9}$/',
message: 'Phone number must be in the format +79151234567'
)]
private string $phoneNumber;

#[Assert\NotBlank(message: 'Phone code cannot be blank')]
#[Assert\Regex(
pattern: '/^\d{4}$/',
message: 'Phone code must be in the format "1234"'
)]
private string $phoneCode;

public function getPhoneNumber(): string
{
return $this->phoneNumber;
}

public function setPhoneNumber(string $phoneNumber): void
{
$this->phoneNumber = $phoneNumber;
}

public function getPhoneCode(): string
{
return $this->phoneCode;
}

public function setPhoneCode(string $phoneCode): void
{
$this->phoneCode = $phoneCode;
}
}
Loading