From 0152c6a2d3721c6ca594172320d83d498f3ca812 Mon Sep 17 00:00:00 2001 From: Wailan Tirajoh <53980548+WailanTirajoh@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:56:26 +0700 Subject: [PATCH] feat: forgot password --- app/Http/Controllers/AuthController.php | 43 +++++++++++++++++++ resources/views/auth/login.blade.php | 2 +- .../views/auth/passwords/email.blade.php | 19 +++++++- ...set.blade.php => reset-password.blade.php} | 19 +++++++- routes/web.php | 14 +++++- 5 files changed, 93 insertions(+), 4 deletions(-) rename resources/views/auth/{passwords/reset.blade.php => reset-password.blade.php} (90%) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index f657444..a83a584 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -3,8 +3,12 @@ namespace App\Http\Controllers; use App\Http\Requests\PostLoginRequest; +use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Auth\Events\PasswordReset; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Password; class AuthController extends Controller { @@ -22,4 +26,43 @@ public function logout() Auth::logout(); return redirect('login')->with('success', 'Logout success, goodbye ' . $name); } + + public function forgotPassword(Request $request) + { + $request->validate(['email' => 'required|email']); + + $status = Password::sendResetLink( + $request->only('email') + ); + + return $status === Password::RESET_LINK_SENT + ? back()->with(['status' => __($status)]) + : back()->withErrors(['email' => __($status)]); + } + + public function resetPassword(Request $request) + { + $request->validate([ + 'token' => 'required', + 'email' => 'required|email', + 'password' => 'required|min:8|confirmed', + ]); + + $status = Password::reset( + $request->only('email', 'password', 'password_confirmation', 'token'), + function (User $user, string $password) { + $user->forceFill([ + 'password' => Hash::make($password) + ])->setRememberToken(Str::random(60)); + + $user->save(); + + event(new PasswordReset($user)); + } + ); + + return $status === Password::PASSWORD_RESET + ? redirect()->route('login')->with('status', __($status)) + : back()->withErrors(['email' => [__($status)]]); + } } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index daf2d5a..9261488 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -84,7 +84,7 @@ class="form-control @error('password') is-invalid @enderror" placeholder="Passwo
Doesnt have any account? register
--}} +Forgot Password? go here
diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 1fea984..18eb46b 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -1,6 +1,23 @@ -@extends('layouts.app') +@extends('template.auth') @section('content') + +