邮件中的密码重置链接错误



我在我的项目上使用多重认证,我的登录页面是:

myurl.com/login

myurl.com/admin/login

myurl.com/login上的密码重置例程工作正常。但是当我在myurl.com/admin/login上尝试时,我在电子邮件上收到的重置链接仍然是:

myurl.com/password/reset/XXXXXXXXXX

但应该是:

myurl.com/admin/password/reset/XXXXXXXXXX

如有任何帮助,不胜感激。

尝试为管理员密码重置创建一个特定的路由,如果没有在代码中指出,单个路由不会采取所有的保护措施。你还必须在AppHttpControllersAuthForgotPasswordController类的通知中指定if条件,通过覆盖IlluminateFoundationAuthSendsPasswordResetEmails trait函数

public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// 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(
$this->credentials($request)
);
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);
}

//或响应函数

protected function sendResetLinkResponse(Request $request, $response)
{
return $request->wantsJson()
? new JsonResponse(['message' => trans($response)], 200)
: back()->with('status', trans($response));
}

验证邮件是否属于admin,并发送相应的链接我个人会更新sendResetLinkEmail函数,并创建另一个函数来发送链接到admin,像这样

$guard = 'user';
$user = User::query()->where('email', $email)->first();
if (!$user) {
$user = Admin::query()->where('email', $email)->first();
$guard = 'admin';
}
if (!$user) {
// This for another case
//    $user = 
//    $guard =
}
// and then, instead of 
//     return $response == Password::RESET_LINK_SENT
//                ? $this->sendResetLinkResponse($request, $response)
//                : $this->sendResetLinkFailedResponse($request,    $response);
// i will do
if ($guard == 'user') {
$success_response = $this->sendResetLinkResponse($request, $response);
} else if ($guard == 'admin') {
$success_response = $this->createAdminResetResponseFunction($request, $response);
} else {
// Set one as default
$success_response = $this->sendResetLinkResponse($request, $response);
}
return $response == Password::RESET_LINK_SENT
? $success_response
: $this->sendResetLinkFailedResponse($request, $response);

感谢大家抽出时间回答。

这就是解决我问题的方法。

我有下面关于AppNotificationsAdminResetPassword的条目:

public function toMail($notifiable)
{
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('admin/password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}

然后我在AppModelsAdmin上定义了这个:

use AppNotificationsAdminResetPassword as ResetPasswordNotification;
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}

在此之后,/loginadmin/login的重置密码链接都工作了。

相关内容

  • 没有找到相关文章