Skip to content

Commit

Permalink
password reset flow
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 4, 2023
1 parent 8de8a73 commit beeaedb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Cone\Root\Http\Controllers\Auth;

use Cone\Root\Http\Controllers\Controller;
use Cone\Root\Notifications\ResetPassword;
use Illuminate\Foundation\Auth\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand All @@ -27,7 +29,9 @@ public function send(Request $request): RedirectResponse
{
$data = $request->validate(['email' => ['required', 'string', 'email']]);

Password::broker()->sendResetLink($data);
Password::broker()->sendResetLink($data, static function (User $user, string $token): void {
$user->notify(new ResetPassword($token));
});

return Redirect::back()->with('status', __(Password::RESET_LINK_SENT));
}
Expand Down
20 changes: 20 additions & 0 deletions src/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Cone\Root\Notifications;

use Illuminate\Auth\Notifications\ResetPassword as Notification;
use Illuminate\Support\Facades\URL;

class ResetPassword extends Notification
{
/**
* Get the reset URL for the given notifiable.
*/
protected function resetUrl(mixed $notifiable): string
{
return URL::route('root.auth.password.reset', [
'token' => $this->token,
'email' => $notifiable->getEmailForPasswordReset(),
]);
}
}

0 comments on commit beeaedb

Please sign in to comment.