Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 4 reset password: sending multiple emails

Tags:

php

laravel

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));
    }
}
like image 474
sterfry68 Avatar asked Feb 14 '23 03:02

sterfry68


1 Answers

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));
    }
}
like image 100
Designated Avatar answered Feb 16 '23 01:02

Designated