laravel中自定义邮件发送重置密码后返回空白页面 - 小众知识

laravel中自定义邮件发送重置密码后返回空白页面

2020-08-19 17:45:40 苏内容
  标签: laravel/密码/邮件
阅读:5407

按如下代码设置重置密码时,在成功发送邮件后返回空白页面,而原版的成功后应该返回We have e-mailed your password reset link!

这是由于我们未设置返回值

<?php



namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

use App\User;

use Illuminate\Auth\Passwords\PasswordBroker;

use Illuminate\Http\Request;



class ForgotPasswordController extends Controller

{

    /*

    |--------------------------------------------------------------------------

    | Password Reset Controller

    |--------------------------------------------------------------------------

    |

    | This controller is responsible for handling password reset emails and

    | includes a trait which assists in sending these notifications from

    | your application to your users. Feel free to explore this trait.

    |

    */



    use SendsPasswordResetEmails;



    /**

     * Create a new controller instance.

     *

     * @return void

     */

    public function __construct()

    {

        $this->middleware('guest');

    }



    //发送重置密码邮件

    public function sendResetLinkEmail(Request $request){

        $user = User::where('email', $request->email)->first();

 

        //实例化一个PasswordBroker类

        //发邮件实际使用的是sendResetLink函数,该函数就在PasswordBroker里

        $password_broker = app(PasswordBroker::class); 

 

        //生成token

        $token = $password_broker->createToken($user); 

        

        //调用User模型中的sendPasswordResetNotification方法发送邮件

        $response = $user->sendPasswordResetNotification($token);

    }

}



修改sendResetLinkEmail,这里不知道如何得到成功状态,暂时都设置为成功,如果发送失败直接提示错误了

    //发送重置密码邮件

    public function sendResetLinkEmail(Request $request){

        $user = User::where('email', $request->email)->first();

 

        //实例化一个PasswordBroker类

        //发邮件实际使用的是sendResetLink函数,该函数就在PasswordBroker里

        $password_broker = app(PasswordBroker::class); 

 

        //生成token

        $token = $password_broker->createToken($user); 

        

        //调用User模型中的sendPasswordResetNotification方法发送邮件

        $user->sendPasswordResetNotification($token);



        $response = PasswordBroker::RESET_LINK_SENT;

        return $response == PasswordBroker::RESET_LINK_SENT

            ? $this->sendResetLinkResponse($response)

            : $this->sendResetLinkFailedResponse($response);

    }




扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1