简体   繁体   中英

How to Change Default Reset Password Link in Laravel 5

I am using a change password functionality in my Laravel 5 Application after the Admin has logged in. I am using the default form provided by laravel for change password functionality which redirects to /userpasswords/email, When the user click on the "Send Password Reset Link". A mail is sent on the mail id but I want to change this url. My url becomes http://localhost/bqs_test/public/index.php/password/reset/1f488a5daf26b57af2d928bb9c0b14e627b34c3459d819f471d402c42f476bf2 which is sent on the email id but I want it to be as http://localhost/bqs_test/public/index.php/userpasswords/reset/1f488a5daf26b57af2d928bb9c0b14e627b34c3459d819f471d402c42f476bf2 . How can I do this, I am new to Laravel, so please someone help. My code is as:

<?php echo Form::open(array('url' => '/userpasswords/email', 'method' => 'post','class'=>'form-horizontal')); ?>
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="form-group">
            <label class="col-md-4 control-label">E-Mail Address</label>
                <div class="col-md-6">
                <input type="email" class="form-control" name="email" value="{{ Auth::user()->email }}" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                <div class="col-md-6 col-md-offset-4">
          <button type="submit" class="btn btn-primary">
            Send Password Reset Link
        </button>
    </div>
</div>

The route defined as:

Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
    'userpasswords' => 'Auth\UserPasswordController'

]);

The UserPasswordController is same as PasswordController but it uses a different trait ResetPasswords which is same as ResetsPasswords with slight change. My postEmail method in ResetPasswords is like:

public function postEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email']);

    $response = $this->passwords->sendResetLink($request->only('email'), function($m)
    {
        $m->subject($this->getEmailSubject());
    });

    switch ($response)
    {
                case PasswordBroker::RESET_LINK_SENT:
                    return redirect()->back()->with('status', trans($response));

                case PasswordBroker::INVALID_USER:
                    return redirect()->back()->withErrors(['email' => trans($response)]);
    }
}

Someone please help how can I change the Url.

you can edit or create this view to change what you want to send

<!-- resources/views/emails/password.blade.php -->
Click here to reset your password: {{ url('userpasswords/reset/'.$token) }}

为了匹配自动生成的身份验证路由,网址应为:

{!! url('password/reset/'.$token) !!}
<?php
namespace App\Http\YourControllers;

use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class YourControllers extends Controller
{
    use SendsPasswordResetEmails;

    public function resetPassLink(Request $request)
    {
        $response = $this->broker()->sendResetLink(['email' => $request->get('email')]);
        if ($response) {
            return view('...')->with('message', 'We have e-mailed your password reset link!');
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM