我在我的项目中使用多身份验证,我的登录页面是:
myurl.com/login和
myurl.com/admin/loginmyurl.com/login上的密码重置例程工作正常。但当我在myurl.com/admin/login上尝试时,我在电子邮件中收到的重置链接仍然是:
myurl.com/password/reset/XXXXXXXXXX但它应该是:
myurl.com/admin/password/reset/XXXXXXXXXX任何帮助都将不胜感激。
发布于 2021-10-02 12:54:12
感谢所有花时间回答问题的人。
这就是解决我的问题的方法。
我在App\Notifications\AdminResetPassword上有下面的条目
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.');
}然后我在我的App\Models\Admin上定义了这个
use App\Notifications\AdminResetPassword as ResetPasswordNotification;
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}在这之后,我的/login和admin/login的重置密码链接都可以工作了。
发布于 2021-10-02 05:13:58
尝试为管理员密码重置创建特定的路由,如果您没有在代码中指明,则单个路由不会占用所有的守卫。您还必须通过覆盖Illuminate\Foundation\Auth\SendsPasswordResetEmails特征函数,在App\Http\Controllers\Auth\ForgotPasswordController类的通知中使用if条件指定它
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));
}验证电子邮件是否属于管理员,并发送适当的链接个人,我会更新sendResetLinkEmail函数,并创建另一个函数来发送链接到管理员像这样
$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);https://stackoverflow.com/questions/69413642
复制相似问题