【问题标题】:Laravel Roles and authentication to routesLaravel 角色和路由身份验证
【发布时间】:2013-05-16 08:12:14
【问题描述】:

我希望归档以下内容

用户登录 -> 从数据库分配权限 -> 他们只能看到允许的路由

到目前为止,我已经能够到达这里:

$user = Usercredential::where('username','=',Auth::user()->username)->get();

foreach ($user as $u ) {

        $status = $u->userstatus;
        $userPriv = $u->userpriviledge;

        if ($status == 0){  
                           Session::put('user_priv',$userPriv);
            }
        else{
                    return Redirect::to_route('home')->with('message','Inactive users cannot login');
            }

它会检查用户的状态是否处于活动状态,然后将权限存储在我的会话中。接下来是什么?我如何保护我的路线?

谢谢

【问题讨论】:

    标签: php authentication laravel laravel-routing


    【解决方案1】:

    对于那些在未来寻找这个解决方案的人

    http://net.tutsplus.com/tutorials/php/build-web-apps-from-scratch-with-laravel-filters-validations-and-files/

    将非常有帮助,感谢 Rodri 的指点。 我很感激。

    【讨论】:

    • 您能否将链接中的相关信息添加到您的答案中?如果链接断开,仅链接的答案可能会变得毫无用处。
    【解决方案2】:

    我向你推荐 Laravel 4 包,名为:ENTRUST,它提供了一种添加基于角色的方法

    【讨论】:

    • 有没有办法使用 Laravel Auth 来做到这一点?
    • 当然可以,请查看文档four.laravel.com/docs/security 并阅读有关过滤器的信息。作为个人观点,我不会尝试在角色和身份验证问题上重新发明轮子,那是因为有人在 Laravel 4 中解决了这个问题。
    猜你喜欢
    • 2018-08-28
    • 2014-02-04
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    相关资源
    最近更新 更多