当前位置: 首页>>代码示例>>PHP>>正文


PHP Sentry::findThrottlerbyUserId方法代码示例

本文整理汇总了PHP中Sentry::findThrottlerbyUserId方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentry::findThrottlerbyUserId方法的具体用法?PHP Sentry::findThrottlerbyUserId怎么用?PHP Sentry::findThrottlerbyUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sentry的用法示例。


在下文中一共展示了Sentry::findThrottlerbyUserId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: function

/**
 * Run all of our preflight tests and authenticate users
 */
Route::filter('snapi_auth', function ($route) {
    // check to see if the model we're after actually exists
    $model = str_singular($route->getParameter('model'));
    if (class_exists($model)) {
        // check to see if we have a valid API key
        if (Input::has('api_key')) {
            // now check to see if the api_key matches exactly one user in the database
            if ($user = User::where('api_key', '=', Input::get('api_key'))->firstOrFail()) {
                // check permissions
                try {
                    $user = Sentry::getUserProvider()->findById($user->id);
                    $action = str_replace('ApiController@', '', $route->getAction());
                    $throttle = Sentry::findThrottlerbyUserId($user->id);
                    $banned = $throttle->isBanned();
                    $suspended = $throttle->isSuspended();
                    // if the user is activated, has access, and is not banned
                    if (!$user->isActivated()) {
                        // User account has not been activated
                        return Response::json(array('error' => 'Your user account has not been activated.'), 403);
                    } elseif ($banned) {
                        // Banned!
                        return Response::json(array('error' => 'Your account has been banned from having access to this resource.'), 403);
                    } elseif ($suspended) {
                        // Suspended!
                        $time = $throttle->getSuspensionTime();
                        $minutes = 1 == $time ? 'minute' : 'minutes';
                        return Response::json(array('error' => "Your account is suspended for {$time} {$minutes}."), 403);
                    } elseif (!$user->hasAccess("{$model}.{$action}")) {
开发者ID:morphatic,项目名称:snapi,代码行数:31,代码来源:routes.php


注:本文中的Sentry::findThrottlerbyUserId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。