このコミットが含まれているのは:
守矢諏訪子 2022-02-18 16:02:23 +09:00
コミット 83e302526b
14個のファイルの変更207行の追加5行の削除

3
backend/.gitignore vendored
ファイルの表示

@ -11,3 +11,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/storage/backup/mysql/*.gz
/storage/backup/mysql/*.sql
/storage/backup/file/*.tar.gz

ファイルの表示

@ -9,6 +9,8 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Models\LoginLimits;
use App\Models\ManageVisiters;
use App\Models\ManageFailureLogins;
trait AuthenticationTrait {
private function makeSession ($guard, $db) {
@ -50,12 +52,19 @@ trait AuthenticationTrait {
public function login (Request $r) {
$loginid = $this->getGuard() == 'children' ? $r->tel : $r->email;
if ($this->getGuard() == 'admins') {
ManageVisiters::create(['ip_address' => $_SERVER['REMOTE_ADDR'], 'host' => gethostbyaddr($_SERVER['REMOTE_ADDR']), 'user_agent' => $_SERVER['HTTP_USER_AGENT']]);
}
if (null !== ($ll = LoginLimits::where('login_id', $loginid)->first())) {
if ((time() >= strtotime($ll->updated_at) + 600) === true) {
LoginLimits::where('login_id', $loginid)->delete();
}
if (null !== ($ll = LoginLimits::where('login_id', $loginid)->first()) && $ll->fail_number >= 10) {
if ($this->getGuard() == 'admins') {
ManageFailureLogins::create(['email' => $loginid, 'password' => Hash::make($r->password)]);
}
return ['status_code' => 400, 'error_message' => ['10回連続で失敗したため、10分間はログインができなくなりました。']];
}
}
@ -89,6 +98,10 @@ trait AuthenticationTrait {
LoginLimits::create(['login_id' => $loginid, 'fail_number' => 1]);
}
if ($this->getGuard() == 'admins') {
ManageFailureLogins::create(['email' => $loginid, 'password' => Hash::make($r->password)]);
}
return ['status_code' => 400, 'error_message' => ['ログインに失敗しました。10回連続で失敗すると、一定期間ログインできなくなります。']];
}
@ -101,6 +114,10 @@ trait AuthenticationTrait {
LoginLimits::create(['login_id' => $loginid, 'fail_number' => 1]);
}
if ($this->getGuard() == 'admins') {
ManageFailureLogins::create(['email' => $loginid, 'password' => Hash::make($r->password)]);
}
return ['status_code' => 400, 'error_message' => ['ログインに失敗しました。10回連続で失敗すると、一定期間ログインできなくなります。']];
}
@ -122,6 +139,9 @@ trait AuthenticationTrait {
setcookie('remember_token', $token, $expire, '/', $_SERVER['HTTP_HOST'], false, true);
}
catch (\Throwable $e) {
if ($this->getGuard() == 'admins') {
ManageFailureLogins::create(['email' => $loginid, 'password' => Hash::make($r->password)]);
}
Log::critical($e->getMessage());
return ['status_code' => 400, 'error_message' => ['ログインに失敗しました。10回連続で失敗すると、一定期間ログインできなくなります。']];
}

12
backend/app/Models/ManageFailureLogins.php ノーマルファイル
ファイルの表示

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ManageFailureLogins extends Model
{
use HasFactory;
protected $fillable = ['email', 'password'];
}

12
backend/app/Models/ManageVisiters.php ノーマルファイル
ファイルの表示

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ManageVisiters extends Model
{
use HasFactory;
protected $fillable = ['ip_address', 'host', 'user_agent'];
}

ファイルの表示

@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ManageFailureLoginsFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

ファイルの表示

@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ManageVisitersFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}

ファイルの表示

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateManageFailureLoginsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('manage_failure_logins', function (Blueprint $table) {
$table->id();
$table->string('email', 255)->unique();
$table->string('password', 255)->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('manage_failure_logins');
}
}

ファイルの表示

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateManageVisitersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('manage_visiters', function (Blueprint $table) {
$table->id();
$table->string('ip_address', 20)->unique();
$table->string('host', 255)->unique();
$table->string('user_agent', 255)->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('manage_visiters');
}
}

ファイルの表示

@ -26,5 +26,9 @@ class AdminsTableSeeder extends Seeder
'email' => 'chankan77@gmail.com',
'password' => Hash::make('A9C6DgfjbJKjUKQtkSrA')
]);
\App\Models\Admin::create([
'email' => 'sa@sa.sa',
'password' => Hash::make('sasasasa')
]);
}
}

ファイルの表示

@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class ManageFailureLoginsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
}
}

ファイルの表示

@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class ManageVisitersSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
}
}

ファイルの表示

@ -9,8 +9,14 @@ services:
web:
image: nginx:1.20-alpine
ports:
- 80:80
- 443:443
- mode: host
protocol: tcp
published: 80
target: 80
- mode: host
protocol: tcp
published: 443
target: 443
volumes:
- ./backend:/work
- /etc/letsencrypt/live/kikikan.xyz:/etc/letsencrypt/live/kikikan.xyz
@ -34,4 +40,4 @@ services:
- db-store:/var/lib/mysql
volumes:
db-store:
db-store:

ファイルの表示

@ -43,10 +43,12 @@ server {
try_files $uri =404;
fastcgi_pass app:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
set_real_ip_from 127.0.0.1/32;
real_ip_header X-Forwarded-For;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}

ファイルの表示

@ -13,7 +13,7 @@ RUN apt-get install -y nodejs
# yarnをインストール
RUN apt-get update
RUN apt-get -y install git unzip libzip-dev libicu-dev libonig-dev zlib1g-dev cron
RUN apt-get -y install git unzip libzip-dev libicu-dev libonig-dev zlib1g-dev cron mariadb-client
RUN apt-get clean
RUN curl --output libpng16-16_1.6.36-6_amd64.deb http://ftp.jp.debian.org/debian/pool/main/libp/libpng1.6/libpng16-16_1.6.36-6_amd64.deb
RUN curl --output libpng-dev_1.6.36-6_amd64.deb http://ftp.jp.debian.org/debian/pool/main/libp/libpng1.6/libpng-dev_1.6.36-6_amd64.deb