Laravel-防止非管理员用户访问仪表板
我正在阻止没有“管理员”角色的用户登录到Laravel 5.5应用程序中的仪表板,如app/http/Controllers/auth/LoginController.php中所示Laravel-防止非管理员用户访问仪表板,laravel,laravel-5,Laravel,Laravel 5,我正在阻止没有“管理员”角色的用户登录到Laravel 5.5应用程序中的仪表板,如app/http/Controllers/auth/LoginController.php中所示 protected function credentials(\Illuminate\Http\Request $request) { $credentials = $request->only($this->username(), 'password');
protected function credentials(\Illuminate\Http\Request $request)
{
$credentials = $request->only($this->username(), 'password');
return array_add($credentials, 'type', 'admin');
}
这工作得很好,但是如果有人使用遗忘密码功能重置密码,那么它会绕过此功能,让他们进入仪表板
如何锁定仪表板以防止发生这种情况
如果在重置密码后禁用自动登录,这是否足够?覆盖
LoginController
中的authenticated
方法。将下面的代码放入LoginController
protected function authenticated(Request $request, $user)
{
if ( Use your Logic here ) {
return redirect()->route('admin.home');
}
return redirect('/home');
}
覆盖
LoginController
中的authenticated
方法。将下面的代码放入LoginController
protected function authenticated(Request $request, $user)
{
if ( Use your Logic here ) {
return redirect()->route('admin.home');
}
return redirect('/home');
}
使用,您将完全控制应用程序中的所有请求
此外,您可能需要查看一下(Spatiale/laravel permission)@github,它将使您的角色/权限过程更加轻松。使用,您将完全控制应用程序中的所有请求
此外,您可能还想看看(Spatiale/laravel permission)@github,它将使您的角色/权限过程变得更加简单。创建一个中间件,如果用户不是管理员,则重定向该用户。如果用户不是管理员,则创建一个中间件重定向该用户。