密码重置在Laravel 5.4中不起作用

时间:2017-04-23 20:04:24

标签: php laravel-5 laravel-5.3 laravel-5.4 email-integration

我是laravel的新手。我想使用laravel auth实现登录和注册。我已经成功实现了登录和注册流程,但我无法实现重置密码。 我面临以下问题: 1.提交用户名/电子邮件后,会发生一些处理,但我无法使用电子邮件发送密码重置链接。它总是有一个屏幕,上面写着我们已经通过电子邮件发送了密码重置链接但没有任何事情发生。条目在password_resets表中进行。 任何帮助将不胜感激。

我正在使用gmail发送密码重置电子邮件。在进行了大量的调试之后,除了执行

之前的ResetPassword.php文件,一切看起来都很好
public function via($notifiable)
{
   // echo "<pre>".print_r($notifiable,1)."</pre>";exit("<br/>sdds");
    return ['mail'];
}

此文件中有一个函数用于发送电子邮件,但此函数不会被调用。功能如下:

 /**
 * Build the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    echo "<pre>".print_r($notifiable,1)."</pre>";exit();
    return (new MailMessage)
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', route('password.reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}

以下是此

中使用的主要文件

授权模型类RetailUserAuth.php

    <?php

   namespace App;

   use Illuminate\Database\Eloquent\Model;
   use Illuminate\Foundation\Auth\User as Authenticatable;
   use Illuminate\Notifications\Notifiable;
   use Illuminate\Foundation\Auth\ResetsPasswords;
   use Illuminate\Auth\Passwords\CanResetPassword;
   class RetailUserAuth extends Authenticatable
   {
     use Notifiable;
     //protected $primaryKey = 'user_id';
protected $table = 'retail_user_auth';
public $timestamps = false;
protected $fillable = ['username', 'user_id', 'password','source','user_status'];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];
}

SendsPasswordResetEmails.php

  <?php

   namespace Illuminate\Foundation\Auth;

   use Illuminate\Http\Request;
   use Illuminate\Support\Facades\Password;

  trait SendsPasswordResetEmails
  {
    /**
    * Display the form to request a password reset link.
    *
    * @return \Illuminate\Http\Response
    */
public function showLinkRequestForm()
{
    return view('auth.passwords.email');
}

/**
 * Send a reset link to the given user.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\RedirectResponse
 */
public function sendResetLinkEmail(Request $request)
{
    $this->validate($request, ['username' => 'required|email']);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink(
        $request->only('username')
    );

    //echo "</pre>".print_r($response,1)."</pre>";exit();
    return $response == Password::RESET_LINK_SENT
                ? $this->sendResetLinkResponse($response)
                : $this->sendResetLinkFailedResponse($request, $response);
}

/**
 * Get the response for a successful password reset link.
 *
 * @param  string  $response
 * @return \Illuminate\Http\RedirectResponse
 */
protected function sendResetLinkResponse($response)
{
    return back()->with('status', trans($response));
}

/**
 * Get the response for a failed password reset link.
 *
 * @param  \Illuminate\Http\Request
 * @param  string  $response
 * @return \Illuminate\Http\RedirectResponse
 */
protected function sendResetLinkFailedResponse(Request $request, $response)
{
    return back()->withErrors(
        ['username' => trans($response)]
    );
}

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

CanResetPassword.php

    <?php

     namespace Illuminate\Auth\Passwords;

     use Illuminate\Auth\Notifications\ResetPassword as 
 ResetPasswordNotification;

  trait CanResetPassword
 {
/**
 * Get the e-mail address where password reset links are sent.
 *
 * @return string
 */
public function getEmailForPasswordReset()
{
    return $this->username;
}

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}
}

ResetPassword.php

   <?php

   namespace Illuminate\Auth\Notifications;

   use Illuminate\Notifications\Notification;
   use Illuminate\Notifications\Messages\MailMessage;

  class ResetPassword extends Notification
{
/**
 * The password reset token.
 *
 * @var string
 */
public $token;

/**
 * Create a notification instance.
 *
 * @param  string  $token
 * @return void
 */
public function __construct($token)
{
    //echo $token;exit('<br/>fdfdffd');
    $this->token = $token;
}

/**
 * Get the notification's channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
   // echo "<pre>".print_r($notifiable,1)."</pre>";exit("<br/>sdds");
    return ['mail'];
}

/**
 * Build the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    echo "<pre>".print_r($notifiable,1)."</pre>";exit();
    return (new MailMessage)
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', route('password.reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}
}

0 个答案:

没有答案