2016-11-08 56 views
2

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

我按照这个教程: Tutorial

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

我该如何解决这个问题?

回答

0

您应该create middleware和重定向所有未激活用户返回到主页,例如:

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

    return $next($request); 
} 

然后register this middleware并将其与Route::group()

+0

Thx,我不能使用默认的中间件? 类验证 { 公共职能手柄($请求,关闭$接下来,$后卫= NULL){ 如果 (AUTH ::后卫($后卫) - >客()){ 如果($请求 - > ajax()|| $ request-> wantsJson()){ return response('Unauthorized。',401);返回重定向() - > guest('login'); } } return $ next($ request); } } – natas

+1

@GabrieleVenturini,你可以使用任何你想要的中间件,只是不要忘记将这个中间件应用到你想要的所有路由。而且,这些路由必须位于'auth'中间件组内。好的做法是为此使用单独的中间件。 –

0

适用于所有非公共途径。如果用户被激活的价值是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。

+0

在我的功能在哪里? – natas