I am using the laravel 10 / Fortify RestUserPassword flow in my login template. Step 2 leads to the email request as per below:
<form action="{{route('password.email')}}" method="post">
@csrf
<div class="input-group mb-3">
<input type="email" class="form-control" placeholder="Email" id="email" name="email">
<div class="input-group-append">
<div class="input-group-text border-left-0 rounded-right" style="border-color:#006600;">
<span class="text-darkgreen fas fa-envelope"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<button type="submit" class="btn btn-darkgreen btn-block">Renouveler votre mot de passe</button>
</div>
</div>
</form>
This works correctly and sends the email to the user requesting the password reset...
I am trying to reproduce this so that the logged-in Admin can also re-issue the email to a currently-edited user like the below:
<form action="{{route('password.email')}}" method="post" class="form-row">
@csrf
<input type="hidden" id="email" name="email" value="{{email-of-the-currently-edited-user}}" >
<button type="submit" class="btn btn-link text-darkgreen">Générer un nouveau mot de passe</button>
<br/>
<small class="text-muted">un mail sera adressé à l'utilisateur pour modifier son mot de passe...</small>
</form>
And this...fails to send the email to the given user!!
You can set other custom route for admin. in your route:
Route::post('/admin/reset-link', [AuthController::class, 'sendResetLink'])->name('admin.reset-link');
in AuthController:
use Illuminate\Support\Facades\Password;
public function sendResetLink(Request $request)
{
$response = Password::sendResetLink(
['email' => $request->input('email')]
);
return $response == Password::RESET_LINK_SENT
? back()->with(['status' => __($response)])
: back()->withErrors(['email' => __($response)]);
}
in your blade:
<form action="{{route('admin.reset-link')}}" method="post" class="form-row">
@csrf
<input type="hidden" id="email" name="email" value="{{email-of-the-currently-edited-user}}">
<button type="submit" class="btn btn-link text-darkgreen">Générer un nouveau mot de passe</button>
<br/>
<small class="text-muted">un mail sera adressé à l'utilisateur pour modifier son mot de passe...</small>
</form>