Support the ongoing development of Laravel.io →
Authentication Mail Installation

By using this Password reminders and reset in Laravel 4 tutorial I tried to add "forgot password" functionality to my website. Using commands *php artisan auth:reminders-controller *and php artisan auth:reminders-migrationswas created RemindersController and migrations file. RemindersController

<?php

class RemindersController extends BaseController {

	public function __construct() {

	}

	protected $layout = 'master';

	/**
	 * Display the password reminder view.
	 *
	 * @return Response
	 */
	public function getRemind()
	{
		$this->layout->content = 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::to('/')->with('status', Lang::get($response));
		}
	}

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

		$this->layout->content = 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)
		{
			dd($user);
			$user->password = Hash::make($password);
			$user->token = null;

			$user->save();
		});

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

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

}

And seems that problems is somewhere in function postReset(), because all the time, at submitting form, I get this case case Password::INVALID_TOKEN..

routes.php

	Route::get('password/reset/{token}', [
		'uses' => 'RemindersController@getReset',
		'as' => 'password.reset'
	]);

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

And reset.blade.php view

@if (Session::has('error'))
  {{ trans(Session::get('reason')) }}
@endif

<div class="register col-lg-4 col-sm-4 col-xs-4">

	{{ Form::open(array('route' => array('password.reset', $token))) }}
	{{-- 
	 {{ Form::open(array('url'=>'password/reset', 'method' => 'post')) }}
	 --}}
		{{ Form::text('email', '', array('class'=>'email form-control', 'placeholder' => 'Email')) }}

		{{ Form::password('password', array('class'=>'password form-control', 'placeholder'=> 'Password')) }}

		{{ Form::password('password_confirmation', array('class'=>'password form-control', 'placeholder' => 'Confirm Password')) }}

		{{ Form::hidden('token', $token) }}

		{{ Form::submit('Submit', array('class'=>'btn btn-info')) }}

	{{ Form::close() }}

</div>

Email has link to that page, containing token:

Last updated 3 years ago.
0

Solved. Problems was that I had wrong timezone and token has expired.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

edogaafx edogaafx Joined 16 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.