0
votes

Have a problem about laravel password reminding.

  1. I can get the link by email from postRemind method in RemindersController controller.

  2. When i click on the reset mail link (http://localhost/projects/mylaravelproject/public/password/reset/d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf)

I get this error : Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

  1. As a conclusion, I am having problem while trying to reach reset.blade page.

    <form action="{{ action('RemindersController@postReset') }}" method="POST">
      <input type="hidden" name="token" value="{{ $token }}">
      <input type="email" name="email">
      <input type="password" name="password">
      <input type="password" name="password_confirmation">
      <input type="submit" value="Reset Password">
    </form>
    

4.This is the whoops preview

  1. This is my routes.php file :
Route::get('/', function()
{
  return View::make('pages.home');
});

//routes to home page when an inner call incomes from the main menu
Route::get('home', [
        'as' => 'home',
        function(){
            return View::make('pages.home');
        }
]);

//routes to about page
Route::get('about', [
        'as' => 'about',
        function(){
            return View::make('pages.about');
        }
]);

//routes to login page
Route::any('login', [
        'as' => 'login',
        function(){
            return View::make('pages.login');
        }
]);

//Routes to forgot password page
Route::any('remindPassword', [
        'as' => 'password.remind',
        function(){
            return View::make('password.remind');
        }
]);

//Forgot Password Post Controller
Route::post('password.remind', [
        'uses' => 'RemindersController@postRemind',
        'as' => 'password.remind.postRemind'
]);

//Routes to register page
Route::any('register', [
        'as' => 'register',
        function(){
            return View::make('pages.register');
        }
]);

//Registration Post Controller
Route::post('register', array(
    'uses' => 'RegistrationController@store',
    'as' => 'registration.store'
));

Route::post('login', array(
  'uses' => 'SessionController@store',
  'as' => 'session.store'
));
Route::get('logout', array(
  'uses' => 'SessionController@destroy',
  'as' => 'session.destroy'
));

Thanks in advance.

2
Did you map the password/reset/{token} route to the correct method of the reminders controller? - Luceos
getReset method in RemindersController has a token and route, if i am not wrong. Like this in getReset method, i have a line like this : return View::make('password.reset')->with('token', $token); and i have that page under Views/password/remind - saimcan
in your html try instead of action route('password.remind.postRemind') - Luceos
How did you get the link in the email to work? Laravel keeps telling me connection refused 61 - kronus

2 Answers

1
votes

That error usually means there is a problem with your routes. Please paste the stack Track or even take a screen shot of the Whoops screen to further look into this.

Also, let us know the routes ( in your route folder for this route )

I will update this Response as i go.

-- UPDATE --

you need to have the actual route in routes.php

Route::post('password/reset/{hash}', ['as' => 'password.reset', 'uses' => 'RemindersController@postReset']);

Then you need to post to that route

<form action="{{ route('password.reset', $hash) }}" method="POST">

$hash is this instance would be the last section of your URL "d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf" I am assuming this is your Password Reset Token

1
votes

I have tried michaelcurry's answer but still wasn't working for me, but thank you everyone for giving me ideas about improving my code. Now it is working, here are the codes :

This is reset.blade page on path Views/password/reset :

<form action="{{ action('RemindersController@postReset') }}" method="POST">
    <input type="hidden" name="token" value="{{ $token }}">
    Email<input type="email" name="email">
    Password<input type="password" name="password">
    Password<input type="password" name="password_confirmation">
    <input type="submit" value="Reset Password">
</form>

This is what i should have in routes.php

//Reset Password Get Controller
Route::get('password/reset/{hash}', array(
    'uses' => 'RemindersController@getReset',
    'as' => 'password.reset',
));

//Reset Password Post Controller
Route::post('password/reset/', [
        'as' => 'password/reset',
        'uses' => 'RemindersController@postReset'
]);

Finally, this is the auto-generated but edited RemindersController controller.

<?php

class RemindersController extends Controller {

    /**
     * Display the password reminder view.
     *
     * @return Response
     */
    public function getRemind()
    {
        return View::make('password.remind');
    }

    /**
     * Handle a POST request to remind a user of their password.
     *
     * @return Response
     */
    public function postRemind()
    {        
        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));
        }
    }

    /**
     * Display the password reset view for the given token.
     *
     * @param  string  $token
     * @return Response
     */
    public function getReset($token = null)
    {
        if (is_null($token)) App::abort(404);

        return View::make('password.reset')->with('token', $token);
    }

    /**
     * Handle a POST request to reset a user's password.
     *
     * @return Response
     */
    public function postReset()
    {
        $credentials = Input::only(
            'email', 'password', 'password_confirmation', 'token'
        );

        $response = Password::reset($credentials, function($user, $password)
        {
            $user->password = Hash::make($password);

            $user->save();
        });

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

            case Password::PASSWORD_RESET:
                return Redirect::to('/');
        }
    }
}

Lastly, thank you for your feedback and patience.