-1

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!!

2
  • Where is the error message? How can we guess your exact issue? You should be very clear about your problem. Otherwise, we can't help you. Commented Oct 29, 2023 at 21:35
  • Hi, The second script (e.g. exactly similar to the first) just does not send the expected email to the 'edited user'... No error messages and no errors logged in the laravel.log either... The script just redirects to the admin home page, as if it were just 'skipping' the "email sending" part ..This is what I do not understand PS: Of course I know there is a passwordUpdate action, but I don't want / cannot use it as I am logged under admin and just want to reset a user's pwd, by sending him a pwd reset link..., just as if he forgot his own pwd,and resets it as per the above 1st script... Commented Oct 30, 2023 at 6:21

1 Answer 1

0

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.