当我的用户在我的应用程序中注册时,它会自动将他们重定向到 /dashboard
,这在技术上是可行的,但它不会检查 confirmed
列是否在数据库的值为1
或0
,它只是根据用户名和密码登录。
我很乐意包含代码,但现在我实际上不知道你们需要看什么代码。
我需要它来检查 confirmed
列,如果它是 0
,而不是让它们登录并抛出错误。
感谢您提供任何信息,
安迪
最佳答案
我通过使用中间件实现了这一点:
我的 routes.php:
Route::get('home', ['middleware' => 'auth', function () {
return "This is just an example";
}]);
我的 Kernel.php:
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
];
我的 Authenticate.php 中间件:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
$user = $this->auth->user();
if (!$user->confirmed) {
$this->auth->logout();
return redirect()->guest('auth/login')->with('error', 'Please confirm your e-mail address to continue.');
}
if (!$user->type) {
$this->auth->logout();
return redirect()->guest('auth/login')->with('error', 'A user configuration error has occurred. Please contact an administrator for assistance.');
}
return $next($request);
}
}
我试着为你尽可能地减少它。
关于php - Laravel 5.1 - 当注册用户应用程序重定向到/dashboard 但不检查帐户是否已确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279389/