0

In my laravel project, i have a forget password system, when i click on forget password and and enter email id , i will recieve password reset link with token on email. But when i clicked on that link its going to 404 page. I have attached sample link which i recieved on email ( https://directory.lifeloveandotherthings.com/public/user/password/reset/1e15c30fcb769f14182cb407861b685bc31a8eb42121b6394049d979beda0753 ).

Following is my codes in routes (web.php)

Route::get('user/password/reset', 'User\UserAuth\ForgotPasswordController@showLinkRequestForm')->name('password.reset');
Route::post('user/password/email', 'User\UserAuth\ForgotPasswordController@sendResetLinkEmail')->name('password.reequest');
Route::post('user/password/reset', 'User\UserAuth\ResetPassswordController@reset')->name('password.email');
Route::get('/password/reset/{token}', 'User\UserAuth\ResetPasswordController@showResetForm');

Following is my code in ResetpasswordController.php

<?php

namespace App\Http\Controllers\User\UserAuth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Illuminate\Http\Request;
use JsValidator;

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    public $redirectTo = '/user/home';

    protected $validationRules = [
                                        'name' => 'required|max:255',
                                        'email' => 'required|email|max:255',
                                        'password' => 'required|min:6|confirmed',
                                    ];


    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
       // $this->middleware('user.guest');
    }

    /**
     * Display the password reset view for the given token.
     *
     * If no token is present, display the link request form.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string|null  $token
     * @return \Illuminate\Http\Response
     */
    public function showResetForm(Request $request, $token = null)
    {
        $validator = JsValidator::make($this->validationRules,[],[],'#resetform');
        return view('user.auth.passwords.reset')->with(
            ['token' => $token, 'email' => $request->email, 'validator' => $validator]
        );
    }

    /**
     * Get the broker to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\PasswordBroker
     */
    public function broker()
    {
        return Password::broker('users');
    }

    /**
     * Get the guard to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard('user');
    }
}

In this resetpassword link controller i have just checked wether the calling is coming to showResetForm Function by echo "hello" in that function, but still its returing 404 not found.

What is the problem here

1
  • Where this route call from Commented Apr 27, 2020 at 10:57

2 Answers 2

0

Something I have run into with password resets is if you are still logged into your system it tries to hit the /home route. You might not have this route anymore and gives you

Sign up to request clarification or add additional context in comments.

Comments

0

You must have slashes or dots in the generated token and Laravel is interpreting your token parameter as a route. Append this regex [\w\s\-_\/\.\$]+ to your Password Reset Controller route and it will work again. This is what I do to fix the problem

Route::get( '/user/reset/password/{token?}', 'CustomResetPasswordController@reset' )->where('token', '[\w\s\-_\/\.\$]+');

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.