我在我的网站上使用Laravel Fortify。它有2个不同的身份验证屏幕管理员和用户。例如:
- 管理员登录路径:/admin/登录
- 管理员忘记密码路由:/admin/忘记密码
- 用户登录路径:/登录
- 用户忘记密码路由:/忘记密码
等等
我正在使用Spatie laravel-permission为一个帐户分配Admin角色,为另一个帐户分配User角色。
一切工作完美,如用户只能从用户登录页面登录,管理员将被重定向到管理员登录页面等登录后管理 Jmeter 板。甚至重置密码实际上也有效。但主要问题是,对于管理员和用户,重置密码链接是相同的。
我想要的是他们有不同的重置密码链接。例如,对于管理员,我希望重置密码链接为127.0.0.1:8000/admin/reset-password/token,对于用户为127.0.0.1:8000/reset-password/token。
我发现这很奇怪,因为我已经为他们做了2个不同的路线,我可以使用php artisan route:list检查,如下所示:Admin RoutesUser Routes
这是我的代码相关的问题:
app\Providers\FortifyServiceProvider.php:
Fortify::requestPasswordResetLinkView(function () {
if (Route::current()->getPrefix() === '/admin') {
return view('auth.admin.forgot-password');
}
return view('auth.forgot-password');
});
Fortify::resetPasswordView(function (Request $request) {
return view('auth.admin.reset-password', ['request' => $request]);
// I didn't check the prefix like requestPasswordLinkView because it will throw error
// the error is caused by not having admin prefix, just as my problem I'm asking now
});
resources\views\auth\admin\login.blade.php:
<form action="{{ route('admin.login') }}" method="POST" class="mb-3">
@csrf
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control @error('email') is-invalid @enderror" id="email" name="email" placeholder="Enter your email address" autofocus>
@error('email') <div class="invalid-feedback">{{ $message }}</div> @enderror
</div>
<div class="mb-3 form-password-toggle">
<div class="d-flex justify-content-between">
<label for="password" class="form-label">Password</label>
<a href="{{ route('admin.password.request') }}">
<small>Forgot Password?</small>
</a>
</div>
<div class="input-group input-group-merge">
<input type="password" class="form-control @error('password') is-invalid @enderror" id="password" name="password" placeholder="············" aria-describedby="password">
<span class="input-group-text cursor-pointer"><i class="ti ti-eye-off"></i></span>
</div>
@error('password') <div class="invalid-feedback d-block">{{ $message }}</div> @enderror
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="remember" name="remember">
<label for="remember" class="form-check-label">Remember Me</label>
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary d-grid w-100">Log In</button>
</div>
</form>
resources\views\auth\admin\forgot-password.blade.php:
<form action="{{ route('admin.password.email') }}" method="POST" class="mb-3">
@csrf
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control @error('email') is-invalid @enderror" id="email" name="email" placeholder="Enter your email address" autofocus>
@error('email') <div class="invalid-feedback">{{ $message }}</div> @enderror
</div>
<button type="submit" class="btn btn-primary d-grid w-100">Send Reset Link</button>
</form>
resources\views\auth\admin\reset-password.blade.php:
<form action="{{ route('admin.password.update') }}" method="POST" class="mb-3">
@csrf
<input type="hidden" name="token" value="{{ $request->route('token') }}">
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control @error('email') is-invalid @enderror" id="email" name="email" value="{{ $request->email ?? old('email') }}" placeholder="Enter your email address" autofocus>
@error('email') <div class="invalid-feedback">{{ $message }}</div> @enderror
</div>
<div class="mb-3 form-password-toggle">
<label for="password" class="form-label">New Password</label>
<div class="input-group input-group-merge">
<input type="password" class="form-control @error('password') is-invalid @enderror" id="password" name="password" placeholder="············" aria-describedby="password">
<span class="input-group-text cursor-pointer"><i class="ti ti-eye-off"></i></span>
</div>
@error('password') <div class="invalid-feedback d-block">{{ $message }}</div> @enderror
</div>
<div class="mb-3 form-password-toggle">
<label for="password" class="form-label">Confirm Password</label>
<div class="input-group input-group-merge">
<input type="password" class="form-control" id="password-confirm" name="password_confirmation" placeholder="············" aria-describedby="password">
<span class="input-group-text cursor-pointer"><i class="ti ti-eye-off"></i></span>
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary d-grid w-100">Reset Password</button>
</div>
</form>
这是我从Mailtrap收到的电子邮件,如果我试图重置管理员的密码:Admin Reset Password Link
这很奇怪我以为链接会有管理员前缀考虑我的路由使用管理员前缀为管理员,但由于某种原因,这没有。有人能帮我指出我做错了什么吗?
2条答案
按热度按时间o3imoua41#
你能做的就是覆盖通知功能。AFAIK,Fortify在引擎盖下使用CanResetPassword trait。因此,在用户模型中,您可以实现自己的逻辑,例如。
您现在可以创建自己的通知,并建立您的链接,因为你的愿望
PS:测试前别忘了
php artisan optimize:clear
bxgwgixi2#
配置目录fortify.php文件有默认的后卫是'网络'你必须改变为“管理”你可以这样做
**app\Providers\FortifyServiceProvider.php:**注册方法