Php Laravel 5.1-注册用户时,应用程序重定向到/仪表板,但不';t检查帐户是否已确认
当我的用户在我的应用程序中注册时,它会自动将他们重定向到Php Laravel 5.1-注册用户时,应用程序重定向到/仪表板,但不';t检查帐户是否已确认,php,authentication,laravel-5,laravel-5.1,laravel-authorization,Php,Authentication,Laravel 5,Laravel 5.1,Laravel Authorization,当我的用户在我的应用程序中注册时,它会自动将他们重定向到/dashboard,这在技术上很好,但它不会检查数据库中的确认的列的值是否为1或0,它只是根据用户名和密码登录 我很乐意包含代码,但现在我不知道你们需要看什么代码 我需要它来检查确认列,如果是0,则不要登录并抛出错误 谢谢你提供的任何信息 Andy我通过使用中间件来实现这一点: <?php namespace App\Http\Middleware; use Closure; use Illuminate\Contracts\A
/dashboard
,这在技术上很好,但它不会检查数据库中的确认的列的值是否为1
或0
,它只是根据用户名和密码登录
我很乐意包含代码,但现在我不知道你们需要看什么代码
我需要它来检查确认
列,如果是0
,则不要登录并抛出错误
谢谢你提供的任何信息
Andy我通过使用中间件来实现这一点:
<?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);
}
}
My routes.php:
Route::get('home', ['middleware' => 'auth', function () {
return "This is just an example";
}]);
My Kernel.php:
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
];
My 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);
}
}
我是通过中间件来实现这一点的
我对Laravel@OliverQueen还是新手你有什么例子吗?我正在使用基本的中间件来阻止未经授权访问仪表板等,但在这方面需要帮助。啊,我会给你我的答案…谢谢,非常感谢:)很好的一个,这很有意义。谢谢:)没问题,很高兴我能帮忙!