Compare commits
19 Commits
8ccbd5000d
...
0.8.1
Author | SHA1 | Date | |
---|---|---|---|
748d05f8fc | |||
b662a85572
|
|||
4368aec1b1 | |||
bd91cdef0c
|
|||
1532cecedc
|
|||
5703015874
|
|||
4bc170ed00
|
|||
20ed4860da
|
|||
e059f09e2f
|
|||
8794b8af4e
|
|||
85e181e51c
|
|||
3f21276ec5 | |||
01153867b3
|
|||
c3bfd4f920 | |||
172a9460df
|
|||
a5ba9eb3f8
|
|||
5ea5d4d0ba | |||
e72dc03589
|
|||
6bf2bc793b
|
75
.env.example
75
.env.example
@@ -1,66 +1,9 @@
|
|||||||
APP_NAME=Laravel
|
DOCKER_NGINX_PORT=8080
|
||||||
APP_ENV=local
|
DOCKER_WEBSOCKET_PORT=8081
|
||||||
APP_KEY=
|
DOCKER_DB_PORT=3306
|
||||||
APP_DEBUG=true
|
MYSQL_ROOT_PASSWORD=root_pass
|
||||||
APP_URL=http://localhost
|
DB_DATABASE=captcha
|
||||||
|
DB_USERNAME=captcha
|
||||||
APP_DEMO_MODE=false
|
DB_PASSWORD=captcha_pass
|
||||||
APP_DEMO_EMAIL=
|
UID=1000
|
||||||
APP_DEMO_PASSWORD=
|
GID=1000
|
||||||
|
|
||||||
APP_DEFAULT_USER_TIMEZONE=UTC
|
|
||||||
# Valid languages: ru | en
|
|
||||||
APP_DEFAULT_LOCALE=ru
|
|
||||||
|
|
||||||
LOG_CHANNEL=daily
|
|
||||||
LOG_DEPRECATIONS_CHANNEL=deprecations
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
|
||||||
DB_HOST=127.0.0.1
|
|
||||||
DB_PORT=3306
|
|
||||||
DB_DATABASE=laravel
|
|
||||||
DB_USERNAME=root
|
|
||||||
DB_PASSWORD=
|
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
|
||||||
CACHE_DRIVER=file
|
|
||||||
FILESYSTEM_DISK=local
|
|
||||||
QUEUE_CONNECTION=sync
|
|
||||||
SESSION_DRIVER=file
|
|
||||||
SESSION_LIFETIME=120
|
|
||||||
|
|
||||||
MEMCACHED_HOST=127.0.0.1
|
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
|
||||||
REDIS_PASSWORD=null
|
|
||||||
REDIS_PORT=6379
|
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
|
||||||
MAIL_HOST=mailpit
|
|
||||||
MAIL_PORT=1025
|
|
||||||
MAIL_USERNAME=null
|
|
||||||
MAIL_PASSWORD=null
|
|
||||||
MAIL_ENCRYPTION=null
|
|
||||||
MAIL_FROM_ADDRESS="hello@example.com"
|
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
|
||||||
|
|
||||||
AWS_ACCESS_KEY_ID=
|
|
||||||
AWS_SECRET_ACCESS_KEY=
|
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
|
||||||
AWS_BUCKET=
|
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
|
||||||
|
|
||||||
PUSHER_APP_ID=
|
|
||||||
PUSHER_APP_KEY=
|
|
||||||
PUSHER_APP_SECRET=
|
|
||||||
PUSHER_HOST=
|
|
||||||
PUSHER_PORT=443
|
|
||||||
PUSHER_SCHEME=https
|
|
||||||
PUSHER_APP_CLUSTER=mt1
|
|
||||||
|
|
||||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
|
||||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|
||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
|
21
.gitignore
vendored
21
.gitignore
vendored
@@ -1,19 +1,6 @@
|
|||||||
/.phpunit.cache
|
|
||||||
/node_modules
|
|
||||||
/public/build
|
|
||||||
/public/hot
|
|
||||||
/public/storage
|
|
||||||
/storage/*.key
|
|
||||||
/vendor
|
|
||||||
.env
|
.env
|
||||||
.env.backup
|
|
||||||
.env.production
|
|
||||||
.phpunit.result.cache
|
|
||||||
Homestead.json
|
|
||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
auth.json
|
Homestead.json
|
||||||
npm-debug.log
|
/.vagrant
|
||||||
yarn-error.log
|
.phpunit.result.cache
|
||||||
/.fleet
|
|
||||||
/.idea
|
|
||||||
/.vscode
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2023 Leonid Nikitin (kor-elf)
|
Copyright (c) 2023 - 2024 Leonid Nikitin (kor-elf)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
76
README.md
76
README.md
@@ -1,66 +1,52 @@
|
|||||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
## О проекте
|
||||||
|
|
||||||
<p align="center">
|
Захотелось написать свой независимый сервис защиты от роботов. Сервис каптча написан на фреймворке Laravel. Вдохновлялся, а так же брал картинки с проекта <a href="https://github.com/wenlng/go-captcha" target="_blank">Go Captcha</a>.
|
||||||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
|
||||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## About Laravel
|
[Сайт проекта](https://service-captcha.projects.kor-elf.net/)
|
||||||
|
|
||||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
## Зависимости
|
||||||
|
|
||||||
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
php 8.3 (модули: redis, gd)
|
||||||
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
|
||||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
|
||||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
|
||||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
|
||||||
- [Robust background job processing](https://laravel.com/docs/queues).
|
|
||||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
|
||||||
|
|
||||||
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
redis
|
||||||
|
|
||||||
## Learning Laravel
|
mysql 8
|
||||||
|
|
||||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
|
## Демострация
|
||||||
|
Демо сервис каптча: https://captcha-admin-demo.tut-site.net/
|
||||||
|
|
||||||
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
|
Email: demo@tut-site.net
|
||||||
|
|
||||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 2000 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
Пароль: demodemo
|
||||||
|
|
||||||
## Laravel Sponsors
|
Демо каптча: https://captcha-demo.tut-site.net/
|
||||||
|
|
||||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
|
## API
|
||||||
|
https://captcha-admin-demo.tut-site.net/api-docs/
|
||||||
|
|
||||||
### Premium Partners
|
## Javascript клиент для сайта
|
||||||
|
https://git.kor-elf.net/kor-elf/service-captcha-gui
|
||||||
|
|
||||||
- **[Vehikl](https://vehikl.com/)**
|
## Как проверять со стороны бэкенда
|
||||||
- **[Tighten Co.](https://tighten.co)**
|
Для Laravel 10, 11 есть готовый пакет: https://git.kor-elf.net/kor-elf/captcha-rule-for-laravel
|
||||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
|
||||||
- **[64 Robots](https://64robots.com)**
|
|
||||||
- **[Cubet Techno Labs](https://cubettech.com)**
|
|
||||||
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
|
||||||
- **[Many](https://www.many.co.uk)**
|
|
||||||
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
|
|
||||||
- **[DevSquad](https://devsquad.com)**
|
|
||||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
|
||||||
- **[OP.GG](https://op.gg)**
|
|
||||||
- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)**
|
|
||||||
- **[Lendio](https://lendio.com)**
|
|
||||||
|
|
||||||
## Contributing
|
Можно установить этот пакет так: composer require kor-elf/captcha-rule-for-laravel
|
||||||
|
|
||||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
<br><b>Curl:</b>
|
||||||
|
|
||||||
## Code of Conduct
|
curl -X POST 'https://captcha-admin-demo.tut-site.net/api/v1/captcha/{captcha-token}' -H 'private-token: {your-private-token}' -H 'Content-Type: application/json' -d '{"user_agent": "{user-agent}"}' --max-time 10
|
||||||
|
|
||||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
Где {captcha-token} - токен получил пользователь от сервиса каптча после успешной проверки.
|
||||||
|
|
||||||
## Security Vulnerabilities
|
Где {your-private-token} - приватный токен, который мы создали в админке.
|
||||||
|
|
||||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
Где {user-agent} - передаём user agent от пользователя, который проходил каптчу.
|
||||||
|
|
||||||
## License
|
Успешная проверка пользователя вернёт ответ код 200 и status = true. Иначе считаем, что пользователь не прошёл проверку на робота.
|
||||||
|
|
||||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
## Репозиторий с демо
|
||||||
|
https://git.kor-elf.net/kor-elf/service-captcha-demo
|
||||||
|
|
||||||
|
## Лицензия
|
||||||
|
|
||||||
|
[MIT license](https://opensource.org/licenses/MIT).
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Private;
|
|
||||||
|
|
||||||
use Illuminate\View\View;
|
|
||||||
|
|
||||||
final class DashboardController extends Controller
|
|
||||||
{
|
|
||||||
public function index(): View
|
|
||||||
{
|
|
||||||
return view('private/dashboard/index');
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Enums\CaptchaLogType;
|
|
||||||
use App\Models\CaptchaLog;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
|
|
||||||
final class CaptchaLogRepository
|
|
||||||
{
|
|
||||||
public function countByType(CaptchaLogType $type, ?int $captchaId = null): int
|
|
||||||
{
|
|
||||||
return CaptchaLog::query()
|
|
||||||
->when($captchaId, function (Builder $query, int $captchaId) {
|
|
||||||
$query->where('captcha_id', $captchaId);
|
|
||||||
})
|
|
||||||
->where('type', '=', $type)
|
|
||||||
->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCaptchaLogsByTypes(array $types, ?int $captchaId = null, ?int $limit = null): Collection
|
|
||||||
{
|
|
||||||
return CaptchaLog::query()
|
|
||||||
->when($captchaId, function (Builder $query, int $captchaId) {
|
|
||||||
$query->where('captcha_id', $captchaId);
|
|
||||||
})
|
|
||||||
->when($limit, function (Builder $query, int $limit) {
|
|
||||||
$query->limit($limit);
|
|
||||||
})
|
|
||||||
->whereIn('type', $types)
|
|
||||||
->latest()
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
}
|
|
92
app/application/.env.example
Normal file
92
app/application/.env.example
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
APP_NAME=Laravel
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
APP_FORCE_HTTPS=false
|
||||||
|
|
||||||
|
APP_CAPTCHA=false
|
||||||
|
CAPTCHA_API_DOMAIN=http://your-domain-captcha-or-IP:8081
|
||||||
|
CAPTCHA_PRIVATE_TOKEN=
|
||||||
|
CAPTCHA_STATIC_PATH=http://your-domain-captcha-or-IP:8081/captcha
|
||||||
|
CAPTCHA_PUBLIC_TOKEN=
|
||||||
|
|
||||||
|
APP_DEMO_MODE=false
|
||||||
|
APP_DEMO_EMAIL=
|
||||||
|
APP_DEMO_PASSWORD=
|
||||||
|
|
||||||
|
APP_DEFAULT_USER_TIMEZONE=UTC
|
||||||
|
# Valid languages: ru | en
|
||||||
|
APP_DEFAULT_LOCALE=ru
|
||||||
|
|
||||||
|
LOG_CHANNEL=daily
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=deprecations
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=db
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=captcha
|
||||||
|
DB_USERNAME=captcha
|
||||||
|
DB_PASSWORD=captcha_pass
|
||||||
|
|
||||||
|
BROADCAST_DRIVER=reverb
|
||||||
|
CACHE_DRIVER=redis
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=redis
|
||||||
|
SESSION_DRIVER=redis
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
|
||||||
|
MEMCACHED_HOST=127.0.0.1
|
||||||
|
|
||||||
|
REDIS_HOST=redis
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=smtp
|
||||||
|
MAIL_HOST=mailpit
|
||||||
|
MAIL_PORT=1025
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
PUSHER_APP_ID=
|
||||||
|
PUSHER_APP_KEY=
|
||||||
|
PUSHER_APP_SECRET=
|
||||||
|
PUSHER_HOST=
|
||||||
|
PUSHER_PORT=443
|
||||||
|
PUSHER_SCHEME=https
|
||||||
|
PUSHER_APP_CLUSTER=mt1
|
||||||
|
|
||||||
|
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||||
|
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||||
|
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||||
|
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||||
|
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||||
|
|
||||||
|
REVERB_APP_ID=
|
||||||
|
REVERB_APP_KEY=
|
||||||
|
REVERB_APP_SECRET=
|
||||||
|
REVERB_HOST="reverb"
|
||||||
|
REVERB_PORT=9000
|
||||||
|
REVERB_SCHEME=http
|
||||||
|
# * or localhost.com or localhost.com, localhost.net
|
||||||
|
REVERB_ALLOWED_ORIGINS="*"
|
||||||
|
|
||||||
|
REVERB_HOST_CLIENT="localhost"
|
||||||
|
REVERB_PORT_CLIENT=8081
|
||||||
|
REVERB_SCHEME_CLIENT=http
|
||||||
|
|
||||||
|
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
|
||||||
|
VITE_REVERB_HOST="${REVERB_HOST}"
|
||||||
|
VITE_REVERB_PORT="${REVERB_PORT}"
|
||||||
|
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
|
19
app/application/.gitignore
vendored
Normal file
19
app/application/.gitignore
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/.phpunit.cache
|
||||||
|
/node_modules
|
||||||
|
/public/build
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/vendor
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
auth.json
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.vscode
|
17
app/application/app/Broadcasting/CreatedCaptchaLog.php
Normal file
17
app/application/app/Broadcasting/CreatedCaptchaLog.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Broadcasting;
|
||||||
|
|
||||||
|
use App\Models\CaptchaToken;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
final readonly class CreatedCaptchaLog
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Authenticate the user's access to the channel.
|
||||||
|
*/
|
||||||
|
public function join(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->can('viewAny', CaptchaToken::class);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Repository\CaptchaLogRepository;
|
||||||
|
|
||||||
|
use App\Enums\CaptchaLogType;
|
||||||
|
|
||||||
|
final class QuantityByDays
|
||||||
|
{
|
||||||
|
private array $days = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $day ("Y-m-d")
|
||||||
|
* @param CaptchaLogType $type
|
||||||
|
* @param int $count
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function add(string $day, CaptchaLogType $type, int $count): void
|
||||||
|
{
|
||||||
|
if (!isset($this->days[$day])) {
|
||||||
|
$this->days[$day] = [];
|
||||||
|
}
|
||||||
|
$this->days[$day][$type->value] = $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $day ("Y-m-d")
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDay(string $day): array
|
||||||
|
{
|
||||||
|
return $this->days[$day] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDays(): array
|
||||||
|
{
|
||||||
|
return $this->days;
|
||||||
|
}
|
||||||
|
}
|
@@ -8,4 +8,9 @@ enum CaptchaLogType: int
|
|||||||
case Error = 2;
|
case Error = 2;
|
||||||
case Verified = 3;
|
case Verified = 3;
|
||||||
case ReadVerified = 4;
|
case ReadVerified = 4;
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return __('captcha_log_type.' . $this->name);
|
||||||
|
}
|
||||||
}
|
}
|
55
app/application/app/Events/CreatedCaptchaLog.php
Normal file
55
app/application/app/Events/CreatedCaptchaLog.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Helpers\Helpers;
|
||||||
|
use App\Models\CaptchaLog;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
final class CreatedCaptchaLog implements ShouldBroadcast
|
||||||
|
{
|
||||||
|
use SerializesModels, Dispatchable;
|
||||||
|
|
||||||
|
public array $chartCaptchaActivity = [];
|
||||||
|
public array $captchaLog = [];
|
||||||
|
|
||||||
|
public function __construct(CaptchaLog $captchaLog) {
|
||||||
|
$this->chartCaptchaActivity = [
|
||||||
|
'date' => $captchaLog->created_at->format('Y-m-d'),
|
||||||
|
'meta' => $captchaLog->type->getTitle(),
|
||||||
|
'type' => $captchaLog->type->value,
|
||||||
|
];
|
||||||
|
$link = '';
|
||||||
|
$title = '';
|
||||||
|
if ($captchaLog->captcha && $captchaLog->captcha->captchaToken) {
|
||||||
|
$link = route('captcha-tokens.edit', ['captcha_token' => $captchaLog->captcha->captcha_token_id], false);
|
||||||
|
$title = $captchaLog->captcha->captchaToken->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ip = $captchaLog->ip;
|
||||||
|
$userAgent = $captchaLog->user_agent;
|
||||||
|
if (Helpers::isDemoMode()) {
|
||||||
|
$ip = __('Demo Mode');
|
||||||
|
$userAgent = __('Demo Mode');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->captchaLog = [
|
||||||
|
'created_at' => $captchaLog->created_at->format("d.m.Y H:i:s"),
|
||||||
|
'link' => $link,
|
||||||
|
'title' => $title,
|
||||||
|
'type' => $captchaLog->type->getTitle(),
|
||||||
|
'ip' => $ip,
|
||||||
|
'user_agent' => $userAgent,
|
||||||
|
'referer' => $captchaLog->referer,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function broadcastOn(): Channel
|
||||||
|
{
|
||||||
|
return new PrivateChannel('chart-captcha-activity');
|
||||||
|
}
|
||||||
|
}
|
@@ -19,7 +19,9 @@ final class AuthController extends Controller
|
|||||||
|
|
||||||
public function login(): View
|
public function login(): View
|
||||||
{
|
{
|
||||||
return view('public/login');
|
return view('public/login', [
|
||||||
|
'captcha' => config('app.captcha', false)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authorization(AuthorizationRequest $request): RedirectResponse
|
public function authorization(AuthorizationRequest $request): RedirectResponse
|
@@ -0,0 +1,43 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Private;
|
||||||
|
|
||||||
|
use App\Http\Resources\Private\Dashboard\ChartCaptchaActivity;
|
||||||
|
use App\Services\Private\DashboardService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class DashboardController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly DashboardService $dashboardService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$limit = 30;
|
||||||
|
$with = ['captcha', 'captcha.captchaToken'];
|
||||||
|
$result = $this->dashboardService->captchaLog($user, $limit, $with);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('private/dashboard/index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function chartCaptchaActivity(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$from = Carbon::now()->subDays(7);
|
||||||
|
$to = Carbon::now();
|
||||||
|
$result = $this->dashboardService->chartCaptchaActivity($user, $from, $to);
|
||||||
|
if (!$result->isSuccess()) {
|
||||||
|
return response()->json($result->getData())->setStatusCode($result->getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(new ChartCaptchaActivity($result));
|
||||||
|
}
|
||||||
|
}
|
@@ -11,7 +11,7 @@ use Illuminate\Http\RedirectResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class UsersController extends Controller
|
final class UsersController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly UserService $userService
|
private readonly UserService $userService
|
@@ -0,0 +1,24 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Private;
|
||||||
|
|
||||||
|
use App\Http\Resources\Private\Websockets\Setting;
|
||||||
|
use App\Services\Private\WebsocketService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
final class WebsocketsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly WebsocketService $websocketService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function settings(): JsonResponse
|
||||||
|
{
|
||||||
|
$result = $this->websocketService->settings();
|
||||||
|
if (!$result->isSuccess()) {
|
||||||
|
return response()->json($result->getData())->setStatusCode($result->getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(new Setting($result));
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user