From f132955be75690804c52b184e72bc535b492f569 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 12 Sep 2019 00:54:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88?= =?UTF-8?q?=E5=89=8A=E9=99=A4=E7=94=BB=E9=9D=A2=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DeactivatedUser.php | 18 +++++++ app/Http/Controllers/SettingController.php | 49 +++++++++++++++++++ app/User.php | 5 ++ ..._003449_create_deactivated_users_table.php | 33 +++++++++++++ resources/assets/js/setting/deactivate.js | 5 ++ resources/views/setting/base.blade.php | 4 +- resources/views/setting/deactivate.blade.php | 32 ++++++++++++ resources/views/setting/deactivated.blade.php | 16 ++++++ routes/web.php | 2 + webpack.mix.js | 1 + 10 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 app/DeactivatedUser.php create mode 100644 database/migrations/2019_11_14_003449_create_deactivated_users_table.php create mode 100644 resources/assets/js/setting/deactivate.js create mode 100644 resources/views/setting/deactivate.blade.php create mode 100644 resources/views/setting/deactivated.blade.php diff --git a/app/DeactivatedUser.php b/app/DeactivatedUser.php new file mode 100644 index 0000000..7cc4b55 --- /dev/null +++ b/app/DeactivatedUser.php @@ -0,0 +1,18 @@ +route('setting.privacy')->with('status', 'プライバシー設定を更新しました。'); } + public function deactivate() + { + return view('setting.deactivate'); + } + + public function destroyUser(Request $request) + { + // パスワードチェック + $validated = $request->validate([ + 'password' => 'required|string' + ]); + + if (!Hash::check($validated['password'], Auth::user()->getAuthPassword())) { + throw ValidationException::withMessages([ + 'password' => 'パスワードが正しくありません。' + ]); + } + + // データの削除 + set_time_limit(0); + DB::transaction(function () { + $user = Auth::user(); + + // 関連レコードの削除 + // TODO: 別にDELETE文相当のクエリを一発発行するだけでもいい? + foreach ($user->ejaculations as $ejaculation) { + $ejaculation->delete(); + } + foreach ($user->likes as $like) { + $like->delete(); + } + + // 先にログアウトしないとユーザーは消せない + Auth::logout(); + + // ユーザーの削除 + $user->delete(); + + // ユーザー名履歴に追記 + DeactivatedUser::create(['name' => $user->name]); + }); + + return view('setting.deactivated'); + } + // ( ◠‿◠ )☛ここに気づいたか・・・消えてもらう ▂▅▇█▓▒░(’ω’)░▒▓█▇▅▂うわあああああああ // public function password() // { diff --git a/app/User.php b/app/User.php index 1cafaa2..c82e5d0 100644 --- a/app/User.php +++ b/app/User.php @@ -53,6 +53,11 @@ class User extends Authenticatable return Auth::check() && $this->id === Auth::user()->id; } + public function ejaculations() + { + return $this->hasMany(Ejaculation::class); + } + public function likes() { return $this->hasMany(Like::class); diff --git a/database/migrations/2019_11_14_003449_create_deactivated_users_table.php b/database/migrations/2019_11_14_003449_create_deactivated_users_table.php new file mode 100644 index 0000000..3e4f475 --- /dev/null +++ b/database/migrations/2019_11_14_003449_create_deactivated_users_table.php @@ -0,0 +1,33 @@ +string('name', 15); + $table->timestamps(); + + $table->primary('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('deactivated_users'); + } +} diff --git a/resources/assets/js/setting/deactivate.js b/resources/assets/js/setting/deactivate.js new file mode 100644 index 0000000..e99acd0 --- /dev/null +++ b/resources/assets/js/setting/deactivate.js @@ -0,0 +1,5 @@ +$('#deactivate-form').on('submit', function () { + if (!confirm('本当にアカウントを削除してもよろしいですか?')) { + return false; + } +}); diff --git a/resources/views/setting/base.blade.php b/resources/views/setting/base.blade.php index d3274cf..2d53e94 100644 --- a/resources/views/setting/base.blade.php +++ b/resources/views/setting/base.blade.php @@ -10,6 +10,8 @@ href="{{ route('setting') }}"> プロフィール プライバシー + アカウントの削除 {{-- パスワード--}} @@ -19,4 +21,4 @@ -@endsection \ No newline at end of file +@endsection diff --git a/resources/views/setting/deactivate.blade.php b/resources/views/setting/deactivate.blade.php new file mode 100644 index 0000000..07df952 --- /dev/null +++ b/resources/views/setting/deactivate.blade.php @@ -0,0 +1,32 @@ +@extends('setting.base') + +@section('title', 'アカウントの削除') + +@section('tab-content') +

アカウントの削除

+
+

Tissueからあなたのアカウントに関する情報を削除します。

+
+

警告

+

削除はすぐに実行され、取り消すことはできません!

+

なりすましを防止するため、あなたのユーザー名はサーバーに記録されます。今後、同じユーザー名を使って再登録することはできません。

+
+ +
+ {{ csrf_field() }} +
+

上記の条件に同意してアカウントを削除する場合は、パスワードを入力して削除ボタンを押してください。

+ + + @if ($errors->has('password')) +
{{ $errors->first('password') }}
+ @endif +
+ + +
+@endsection + +@push('script') + +@endpush diff --git a/resources/views/setting/deactivated.blade.php b/resources/views/setting/deactivated.blade.php new file mode 100644 index 0000000..1e5fafa --- /dev/null +++ b/resources/views/setting/deactivated.blade.php @@ -0,0 +1,16 @@ +@extends('layouts.base') + +@section('title', 'アカウント削除完了') + +@section('content') +
+

アカウントを削除しました

+
+

Tissueをご利用いただき、ありがとうございました。

+

トップページへ

+
+@endsection + +@push('script') + +@endpush diff --git a/routes/web.php b/routes/web.php index 6c0fbdb..184bd18 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,6 +36,8 @@ Route::middleware('auth')->group(function () { Route::post('/setting/profile', 'SettingController@updateProfile')->name('setting.profile.update'); Route::get('/setting/privacy', 'SettingController@privacy')->name('setting.privacy'); Route::post('/setting/privacy', 'SettingController@updatePrivacy')->name('setting.privacy.update'); + Route::get('/setting/deactivate', 'SettingController@deactivate')->name('setting.deactivate'); + Route::post('/setting/deactivate', 'SettingController@destroyUser')->name('setting.deactivate.destroy'); // Route::get('/setting/password', 'SettingController@password')->name('setting.password'); }); diff --git a/webpack.mix.js b/webpack.mix.js index 3532d8b..bf24e44 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -16,6 +16,7 @@ mix.js('resources/assets/js/app.js', 'public/js') .js('resources/assets/js/home.js', 'public/js') .js('resources/assets/js/user/stats.js', 'public/js/user') .js('resources/assets/js/setting/privacy.js', 'public/js/setting') + .js('resources/assets/js/setting/deactivate.js', 'public/js/setting') .ts('resources/assets/js/checkin.ts', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .autoload({