【问题标题】:Disabled user / Validation Email禁用用户/验证电子邮件
【发布时间】:2017-03-21 23:08:49
【问题描述】:

我在用户数据库中添加了一个列(is_activated),用于在注册过程中添加验证电子邮件。

我遵循本教程: Tutorial

它可以工作,但未激活的用户可以使用重置密码表单绕过登录功能。

我该如何解决这个问题?

【问题讨论】:

    标签: laravel authentication laravel-5.2


    【解决方案1】:

    您应该create middleware 并将所有未激活的用户重定向回主页,例如:

    public function handle($request, Closure $next)
    { 
        if (!auth()->user()->is_activated) {
            return redirect('/');
        }
    
        return $next($request);
    }
    

    然后register this middleware 并用Route::group() 将其应用于所有非公共路由

    【讨论】:

    • 谢谢,我不能使用默认的中间件?类认证 { 公共函数句柄($request,关闭 $next,$guard = null) { if (Auth::guard($guard)->guest()) { if ($request->ajax() || $request ->wantsJson()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } 返回 $next($request); } }
    • @GabrieleVenturini,你可以使用任何你想要的中间件,只是不要忘记把这个中间件应用到你想要的所有路由上。此外,这些路由必须在 auth 中间件组内。好的做法是为此使用单独的中间件。
    【解决方案2】:

    如果用户被激活,则值为 1,因此在您的函数中集成下一个验证:

    // if user not have value 1 (is not activated)
    if (auth()->user()->is_activated != 1) {
        // user is not activated so redirect to index
        return redirect('/');
    }
    // user is activated so redirect to account 
    return redirect('account');
    

    }

    您需要检查"is_actived" 的值是否为 1。

    【讨论】:

    • 我的函数在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 2019-07-05
    相关资源
    最近更新 更多