diff --git a/Modules/Profile/routes/web.php b/Modules/Profile/routes/web.php index 489e3f66a..3b202e1e3 100644 --- a/Modules/Profile/routes/web.php +++ b/Modules/Profile/routes/web.php @@ -5,5 +5,5 @@ use Modules\Profile\Http\Controllers\ProfileController; Route::middleware('auth')->prefix('profile')->name('profile.')->group(function () { Route::get('/', [ProfileController::class, 'show'])->name('show'); Route::get('/edit', [ProfileController::class, 'edit'])->name('edit'); - Route::put('/', [ProfileController::class, 'update'])->name('update'); + Route::put('/extended', [ProfileController::class, 'update'])->name('update'); }); diff --git a/app/Http/Controllers/Auth/ProfileController.php b/app/Http/Controllers/Auth/ProfileController.php new file mode 100644 index 000000000..6ab3c68eb --- /dev/null +++ b/app/Http/Controllers/Auth/ProfileController.php @@ -0,0 +1,54 @@ +validateWithBag('updateProfile', [ + 'name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique('users')->ignore($request->user()->id)], + ]); + + $request->user()->fill($validated); + + if ($request->user()->isDirty('email')) { + $request->user()->email_verified_at = null; + } + + $request->user()->save(); + + return redirect('/profile')->with('status', 'profile-updated'); + } + + /** + * Delete the user's account. + */ + public function destroy(Request $request): RedirectResponse + { + $request->validateWithBag('userDeletion', [ + 'password' => ['required', 'current_password'], + ]); + + $user = $request->user(); + + Auth::logout(); + + $user->delete(); + + $request->session()->invalidate(); + $request->session()->regenerateToken(); + + return redirect('/'); + } +} diff --git a/routes/auth.php b/routes/auth.php index 3926ecf72..12e77f40f 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -54,6 +54,9 @@ Route::middleware('auth')->group(function () { Route::put('password', [PasswordController::class, 'update'])->name('password.update'); + Route::patch('profile', [\App\Http\Controllers\Auth\ProfileController::class, 'update'])->name('profile.update'); + Route::delete('profile', [\App\Http\Controllers\Auth\ProfileController::class, 'destroy'])->name('profile.destroy'); + Route::post('logout', [AuthenticatedSessionController::class, 'destroy']) ->name('logout'); }); diff --git a/routes/web.php b/routes/web.php index 6eeeebfb4..c13e0ff89 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Partner\DashboardController; use App\Http\Controllers\Partner\ListingController as PartnerListingController; Route::get('/', [HomeController::class, 'index'])->name('home'); +Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard')->middleware('auth'); Route::get('/lang/{locale}', [LanguageController::class, 'switch'])->name('lang.switch'); Route::middleware('auth')->prefix('partner')->name('partner.')->group(function () { diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 8364a84e2..22ef0c599 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -2,11 +2,13 @@ namespace Tests\Feature; -// use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class ExampleTest extends TestCase { + use RefreshDatabase; + /** * A basic test example. */