diff --git a/app/Livewire/Auth/ForgotPassword.php b/app/Livewire/Auth/ForgotPassword.php new file mode 100644 index 0000000..cc75872 --- /dev/null +++ b/app/Livewire/Auth/ForgotPassword.php @@ -0,0 +1,38 @@ + 'Lupa Kata Sandi', +])] +class ForgotPassword extends Component +{ + use WithToast; + + #[Validate(['required', 'string'])] + public string $email = ''; + + public function sendLink() + { + $this->validate(); + + $status = Password::sendResetLink( + $this->only('email') + ); + + return $status === Password::ResetLinkSent + ? $this->toast(__($status), 'Berhasil') + : $this->toast(__($status), 'Gagal', 'danger'); + } + + public function render() + { + return view('livewire.auth.forgot-password'); + } +} diff --git a/app/Livewire/Auth/Login.php b/app/Livewire/Auth/Login.php index ac30967..08f183c 100644 --- a/app/Livewire/Auth/Login.php +++ b/app/Livewire/Auth/Login.php @@ -21,6 +21,18 @@ class Login extends Component #[Validate('required', attribute: 'kata sandi')] public string $password = ''; + public function mount() + { + if (request()->has('message')) { + $this->toast(request('message')); + $this->js(" + const url = new URL(window.location); + url.search = ''; + window.history.replaceState({}, '', url); + "); + } + } + public function auth() { $this->validate(); diff --git a/app/Livewire/Auth/ResetPassword.php b/app/Livewire/Auth/ResetPassword.php new file mode 100644 index 0000000..1efe01c --- /dev/null +++ b/app/Livewire/Auth/ResetPassword.php @@ -0,0 +1,47 @@ + 'Atur Ulang Kata Sandi', +])] +class ResetPassword extends Component +{ + use WithToast; + + public ResetPasswordForm $form; + + #[Url] + public $token = ''; + + #[Url] + public $email = ''; + + public function mount() + { + $this->form->setTokenAndEmail($this->token, $this->email); + } + + public function resetPassword() + { + $status = $this->form->store(); + + return $status === Password::PasswordReset + ? $this->redirectRoute('login', [ + 'message' => 'Kata sandi berhasil diperbarui, silakan masuk kembali.', + ], navigate: true) + : $this->toast(__($status), 'Gagal', 'danger'); + } + + public function render() + { + return view('livewire.auth.reset-password'); + } +} diff --git a/app/Livewire/Forms/Auth/ResetPasswordForm.php b/app/Livewire/Forms/Auth/ResetPasswordForm.php new file mode 100644 index 0000000..2a2f920 --- /dev/null +++ b/app/Livewire/Forms/Auth/ResetPasswordForm.php @@ -0,0 +1,64 @@ + 'required', + 'email' => ['required', 'email'], + 'password' => ['required', 'string', 'min:8', 'confirmed'], + 'password_confirmation' => ['required', 'string', 'min:8', 'same:password'], + ]; + } + + public function validationAttributes(): array + { + return [ + 'password' => 'kata sandi', + 'password_confirmation' => 'konfirmasi kata sandi', + ]; + } + + public function setTokenAndEmail(string $token, string $email) + { + $this->token = $token; + $this->email = $email; + } + + public function store() + { + $this->validate(); + + $status = Password::reset( + $this->only('email', 'password', 'password_confirmation', 'token'), + function (User $user, string $password) { + $user->forceFill([ + 'password' => Hash::make($password), + ]); + + $user->save(); + + event(new PasswordReset($user)); + } + ); + + return $status; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 452e6b6..5cf9c33 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\Models\User; +use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -19,6 +21,8 @@ public function register(): void */ public function boot(): void { - // + ResetPassword::createUrlUsing(function (User $user, string $token) { + return config('app.url').'/auth/reset-password?token='.$token.'&email='.$user->email; + }); } } diff --git a/resources/views/livewire/auth/forgot-password.blade.php b/resources/views/livewire/auth/forgot-password.blade.php new file mode 100644 index 0000000..b0915e9 --- /dev/null +++ b/resources/views/livewire/auth/forgot-password.blade.php @@ -0,0 +1,39 @@ +
+
+
+
+ + +
+ YD +
+
+
+
+ + Lupa Kata Sandi? + + Silakan masukkan alamat email Anda. Kami akan mengirimkan instruksi untuk mengatur ulang kata sandi. + + +
+ + + Kirim Tautan + +
+ + Sudah ingat kata sandi? Masuk + + +
+
+ +
+
+
+
+
diff --git a/resources/views/livewire/auth/login.blade.php b/resources/views/livewire/auth/login.blade.php index be9299a..1444161 100644 --- a/resources/views/livewire/auth/login.blade.php +++ b/resources/views/livewire/auth/login.blade.php @@ -25,7 +25,9 @@ class="size-8 rounded shrink-0 bg-accent text-accent-foreground flex items-cente
Kata Sandi - Lupa kata sandi? + Lupa kata + sandi?
diff --git a/resources/views/livewire/auth/reset-password.blade.php b/resources/views/livewire/auth/reset-password.blade.php new file mode 100644 index 0000000..527de93 --- /dev/null +++ b/resources/views/livewire/auth/reset-password.blade.php @@ -0,0 +1,43 @@ +
+
+
+
+ + +
+ YD +
+
+
+
+ + Atur Ulang Kata Sandi + + Silakan masukkan kata sandi baru Anda untuk mengatur ulang kata sandi Anda. + + +
+ + + + + Atur Ulang + +
+ + + Sudah ingat kata sandi? Masuk + + +
+
+ +
+
+
+
+
diff --git a/routes/pages/auth.php b/routes/pages/auth.php index c92ef97..deb3476 100644 --- a/routes/pages/auth.php +++ b/routes/pages/auth.php @@ -1,8 +1,10 @@ group(function () { Route::get('login', LoginComponent::class)->name('login'); Route::get('register', RegisterComponent::class)->name('register'); + + Route::get('forgot-password', ForgotPasswordComponent::class)->name('password.request'); + + Route::get('reset-password', ResetPasswordComponent::class)->name('password.reset'); }); Route::post('logout', LogoutComponent::class)->name('logout')->middleware('auth');