アカウント削除画面の追加

This commit is contained in:
shibafu 2019-09-12 00:54:36 +09:00
parent a71aa0c3b6
commit f132955be7
10 changed files with 164 additions and 1 deletions

18
app/DeactivatedUser.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* 削除済Userのユーザー名履歴
*/
class DeactivatedUser extends Model
{
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'name'
];
}

View File

@ -2,10 +2,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\DeactivatedUser;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
class SettingController extends Controller class SettingController extends Controller
{ {
@ -67,6 +71,51 @@ class SettingController extends Controller
return redirect()->route('setting.privacy')->with('status', 'プライバシー設定を更新しました。'); return redirect()->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() // public function password()
// { // {

View File

@ -53,6 +53,11 @@ class User extends Authenticatable
return Auth::check() && $this->id === Auth::user()->id; return Auth::check() && $this->id === Auth::user()->id;
} }
public function ejaculations()
{
return $this->hasMany(Ejaculation::class);
}
public function likes() public function likes()
{ {
return $this->hasMany(Like::class); return $this->hasMany(Like::class);

View File

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

View File

@ -0,0 +1,5 @@
$('#deactivate-form').on('submit', function () {
if (!confirm('本当にアカウントを削除してもよろしいですか?')) {
return false;
}
});

View File

@ -10,6 +10,8 @@
href="{{ route('setting') }}"><span class="oi oi-person mr-1"></span> プロフィール</a> href="{{ route('setting') }}"><span class="oi oi-person mr-1"></span> プロフィール</a>
<a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'setting.privacy' ? 'active' : '' }}" <a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'setting.privacy' ? 'active' : '' }}"
href="{{ route('setting.privacy') }}"><span class="oi oi-shield mr-1"></span> プライバシー</a> href="{{ route('setting.privacy') }}"><span class="oi oi-shield mr-1"></span> プライバシー</a>
<a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'setting.deactivate' ? 'active' : '' }}"
href="{{ route('setting.deactivate') }}"><span class="oi oi-trash mr-1"></span> アカウントの削除</a>
{{--<a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'setting.password' ? 'active' : '' }}" {{--<a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'setting.password' ? 'active' : '' }}"
href="{{ route('setting.password') }}"><span class="oi oi-key mr-1"></span> パスワード</a>--}} href="{{ route('setting.password') }}"><span class="oi oi-key mr-1"></span> パスワード</a>--}}
</div> </div>

View File

@ -0,0 +1,32 @@
@extends('setting.base')
@section('title', 'アカウントの削除')
@section('tab-content')
<h3>アカウントの削除</h3>
<hr>
<p>Tissueからあなたのアカウントに関する情報を削除します。</p>
<div class="alert alert-danger">
<h4 class="alert-heading"><span class="oi oi-warning"></span> 警告</h4>
<p><strong>削除はすぐに実行され、取り消すことはできません!</strong></p>
<p class="my-0">なりすましを防止するため、あなたのユーザー名はサーバーに記録されます。今後、同じユーザー名を使って再登録することはできません。</p>
</div>
<form id="deactivate-form" action="{{ route('setting.deactivate.destroy') }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<p>上記の条件に同意してアカウントを削除する場合は、パスワードを入力して削除ボタンを押してください。</p>
<input name="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" required>
@if ($errors->has('password'))
<div class="invalid-feedback">{{ $errors->first('password') }}</div>
@endif
</div>
<button type="submit" class="btn btn-danger mt-2">削除</button>
</form>
@endsection
@push('script')
<script src="{{ mix('js/setting/deactivate.js') }}"></script>
@endpush

View File

@ -0,0 +1,16 @@
@extends('layouts.base')
@section('title', 'アカウント削除完了')
@section('content')
<div class="container">
<h3>アカウントを削除しました</h3>
<hr>
<p>Tissueをご利用いただき、ありがとうございました。</p>
<p class="my-5 text-center"><a class="btn btn-link" href="{{ route('home') }}">トップページへ</a></p>
</div>
@endsection
@push('script')
<script src="{{ mix('js/setting/deactivate.js') }}"></script>
@endpush

View File

@ -36,6 +36,8 @@ Route::middleware('auth')->group(function () {
Route::post('/setting/profile', 'SettingController@updateProfile')->name('setting.profile.update'); Route::post('/setting/profile', 'SettingController@updateProfile')->name('setting.profile.update');
Route::get('/setting/privacy', 'SettingController@privacy')->name('setting.privacy'); Route::get('/setting/privacy', 'SettingController@privacy')->name('setting.privacy');
Route::post('/setting/privacy', 'SettingController@updatePrivacy')->name('setting.privacy.update'); 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'); // Route::get('/setting/password', 'SettingController@password')->name('setting.password');
}); });

1
webpack.mix.js vendored
View File

@ -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/home.js', 'public/js')
.js('resources/assets/js/user/stats.js', 'public/js/user') .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/privacy.js', 'public/js/setting')
.js('resources/assets/js/setting/deactivate.js', 'public/js/setting')
.ts('resources/assets/js/checkin.ts', 'public/js') .ts('resources/assets/js/checkin.ts', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css') .sass('resources/assets/sass/app.scss', 'public/css')
.autoload({ .autoload({