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') + +