Laravel 5.1 - 注册用户时应用重定向到 /dashboard 但不检查帐户是不是已确认
Posted
技术标签:
【中文标题】Laravel 5.1 - 注册用户时应用重定向到 /dashboard 但不检查帐户是不是已确认【英文标题】:Laravel 5.1 - When registering user App redirects to /dashboard but doesn't check if account is confirmedLaravel 5.1 - 注册用户时应用重定向到 /dashboard 但不检查帐户是否已确认 【发布时间】:2016-05-18 16:34:52 【问题描述】:当我的用户在我的应用程序中注册时,它会自动将他们重定向到 /dashboard
,这在技术上没问题,但它不会检查数据库中的 confirmed
列是否具有 1
或 @987654324 的值@,只是根据用户名和密码登录。
我很乐意包含代码,但现在我实际上并不知道你们需要查看哪些代码。
我需要它来检查confirmed
列,如果它是0
,而不是让它们登录并抛出错误。
感谢您提供任何信息,
安迪
【问题讨论】:
我通过middleware
实现了这一点
我还是 Laravel 的新手 @OliverQueen 你有任何例子吗?我正在使用基本的中间件来阻止对仪表板等的未经授权的访问,但需要帮助解决这个注册重定向问题
是的,我会告诉你我的答案......
谢谢,非常感谢 :)
【参考方案1】:
我通过使用中间件来实现这一点:
我的路线.php:
Route::get('home', ['middleware' => 'auth', function ()
return "This is just an example";
]);
我的内核.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);
我试图为你尽可能地减少这个。
【讨论】:
很好,这很有意义。谢谢你:) 没问题,很高兴我能帮上忙!以上是关于Laravel 5.1 - 注册用户时应用重定向到 /dashboard 但不检查帐户是不是已确认的主要内容,如果未能解决你的问题,请参考以下文章