php-Laravel 5.1-注册用户应用程序时重定向到/ dashboard,但不检查帐户是否已确认
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-Laravel 5.1-注册用户应用程序时重定向到/ dashboard,但不检查帐户是否已确认,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1620字,纯文字阅读大概需要3分钟。
内容图文
![php-Laravel 5.1-注册用户应用程序时重定向到/ dashboard,但不检查帐户是否已确认](/upload/InfoBanner/zyjiaocheng/664/1bb938535bc344e49ecf6938c7968bdc.jpg)
当我的用户在我的应用程序中注册时,它会自动将他们重定向到/ dashboard,这在技术上来说还不错,但是它不会检查数据库中已确认的列的值是1还是0,它只是基于用户名登录和密码.
我会很高兴地包含代码,但是现在我实际上并不知道你们需要看什么代码.
我需要它来检查已确认的列,如果它是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,但不检查帐户是否已确认全部内容,希望文章能够帮你解决php-Laravel 5.1-注册用户应用程序时重定向到/ dashboard,但不检查帐户是否已确认所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。