首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何防止两个Laravel中间件创建无休止的重定向?

如何防止两个Laravel中间件创建无休止的重定向?
EN

Stack Overflow用户
提问于 2018-09-27 11:50:27
回答 1查看 67关注 0票数 4

我有两个中间件,它们不是路由中间件。它们专门用来确保登录用户的两件事都准备就绪。付款和签署的单据。

我的kernel.php:

代码语言:javascript
复制
    protected $middleware = [
    'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
    'Illuminate\Cookie\Middleware\EncryptCookies',
    'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
    'Illuminate\Session\Middleware\StartSession',
    'Illuminate\View\Middleware\ShareErrorsFromSession',
    'App\Http\Middleware\VerifyCsrfToken',
    'App\Http\Middleware\AuthenticateSigned',
    'App\Http\Middleware\FeesOwed',
    'App\Http\Middleware\DeniedAccess'
];

造成此问题的是AuthenticateSigned和FeesOwed

第一个AuthenticateSigned:

代码语言:javascript
复制
public function handle($request, Closure $next)
{
    if ($this->auth->guest())
    {
        if ($request->ajax()){
            return response('Unauthorized.', 401);
        } else {
            return redirect()->guest('login');
        }

    } else if(!$this->auth->user()->role->administrator){ // the users not an admin

        if(!$this->auth->user()->agreement_id || $this->auth->user()->signed_current_membership_agmt == 0 ){
            if ($request->ajax()){
                return response('Unauthorized.', 401);
            } else {
                return redirect()->route('agreement');
            }
        }

        return $next($request);

    } 

    return $next($request);

}

然后是我的FeesOwed:

代码语言:javascript
复制
public function handle($request, Closure $next)
{

    $uri = $request->server()['REQUEST_URI'];

    if($this->auth->user() 
        && $this->auth->user()->role_id != 3
        && $this->auth->user()->unpaidFees() // Does the user have past due fees
        && $uri != '/profile/investment-fees' // view of form to pay fees
        && $uri != '/profile/charge-investment-fees' // post request to pay fees
        && $uri != '/profile/pay-payment'

        && $uri != '/logout'
        //&& !$this->auth->user()->role->administrator // admins shouldn't be subject to this
        ){
        \Session::flash('message','You must pay past due management fees before using the rest of the members platform.');

        return redirect()->route('profile.investment-fees');
    } 

    return $next($request);
}

我已经阅读了大量的SO帖子和视频,所有的笔记要么是"your missing a return $next($request);",要么是路由中间件。

这些中间件一直在运行,因为有时用户知道他们需要签署新协议或支付费用是很重要的。

任何帮助都是非常感谢的。谢谢

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52529169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档