4

I've implemented Laravel's standard password reset functionality in my app. It works nicely except that I'm getting 2 "reset password" emails in my inbox. (Side note that might not mean anything: one of the emails doesn't have a subject line and the other does.) I don't think I'm doing anything out of the ordinary so I'm stumped. Any ideas?

public function getRemind(){
    $view = View::make('password.remind');
    $view->title = 'my title';

    return $view;
}

form on remind.blade.php

{{ Form::open(array('url'=>'do-reset')) }}

        <fieldset>
            <label for="email">Email Address</label>
            {{ Form::email('email', $email, array('id'=>'email')) }}

            <div id="button_wrap">
                <input type="submit" id="submit" name="submit" value="Send Reset Email">
            </div>

        </fieldset>

        @if(Session::has('status'))
            <p>{{ Session::get('status') }}</p>
        @endif

        @if(Session::has('error'))
            <p>{{ Session::get('error') }}</p>
        @endif

    {{ Form::close() }}

Route for do-reset:

Route::post('do-reset', array('uses'=>'RemindersController@postRemind'));

I haven't changed anything in the postRemind() method:

public function postRemind(){
    Password::remind(Input::only('email'), function($message){
        $message->subject('Click on the link below to reset your password.');
    });

    switch ($response = Password::remind( Input::only('email') ) ){
        case Password::INVALID_USER:
            return Redirect::back()->with('error', Lang::get($response));

        case Password::REMINDER_SENT:
            return Redirect::back()->with('status', Lang::get($response));
    }
}
2
  • Are you double clicking the submit button? Commented Apr 21, 2014 at 17:55
  • Nope - guess it's good to start with the obvious. Commented Apr 21, 2014 at 17:59

1 Answer 1

8

As you can probably see the Password::remind() function is being called twice. I would change the code to something like this:

public function postRemind()
{
    $response = Password::remind(Input::get('email'), function($message) {
        $message->subject('Click on the link below to reset your password.');
    });

    switch ($response) {
        case Password::INVALID_USER:
            return Redirect::back()->with('error', Lang::get($response));

        case Password::REMINDER_SENT:
            return Redirect::back()->with('status', Lang::get($response));
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Nice catch. I guess I didn't look at it very carefully because I didn't change anything and I assumed that the code was right. You know what they say about that word: ASS.U.ME. Thanks!

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.