博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
laravel5通过auth.attempt事件加入登陆验证码
阅读量:7294 次
发布时间:2019-06-30

本文共 1201 字,大约阅读时间需要 4 分钟。

auth = $auth; $this->registrar = $registrar; //注册auth.attemp事件 //加入验证码的验证 $this->auth->attempting(function()use($request){ $phrase = \Session::get('phrase'); if($request->input('phrase') != $phrase){ throw new HttpResponseException( redirect('/auth/login')->withInput($request->input())->withErrors(['phrase'=>'验证码错误']) ); } }); $this->middleware('guest', ['except' => 'getLogout']); }}

需要特别说明的是HttpResponseException这个异常,这个异常接收一个Response作为参数,在Illuminate\Routing\Route的run方法中会捕获这个异常并返回设置的Response,所以我们可以通过抛出这个异常来终止我们的应用程序并跳转

public function run(Request $request)    {        $this->container = $this->container ?: new Container;        try        {            if ( ! is_string($this->action['uses']))                return $this->runCallable($request);            if ($this->customDispatcherIsBound())                return $this->runWithCustomDispatcher($request);            return $this->runController($request);        }        catch (HttpResponseException $e)        {            return $e->getResponse();        }    }

 

转载于:https://www.cnblogs.com/xiaodo0/p/4397982.html

你可能感兴趣的文章
ORM简介
查看>>
so 问题来了,你现在值多少钱?
查看>>
17.3. mpstat
查看>>
dataguard中MRP无法启动的问题分析和解决
查看>>
Oracle 12C R2-新特性-转换函数的增强
查看>>
ITIL的一些简单感受
查看>>
使用oracheck进行系统巡检
查看>>
云计算+物联网的前景更加诱人
查看>>
SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因...
查看>>
购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(2)--前端,以及前后端Session
查看>>
HDOJ/HDU 2566 统计硬币(公式~遍历~)
查看>>
Java RMI(远程方法调用) 实例与分析 (转)
查看>>
架构漫谈(二):认识概念是理解架构的基础
查看>>
[20161219]关于LANGUAGE_MISMATCH.txt
查看>>
天使投资乱象频出 熟人元素何时剔除
查看>>
使用SQLCMD在SQLServer执行多个脚本
查看>>
如何使用通用Mapper
查看>>
快速安装及部署DRBD
查看>>
Java调试那点事
查看>>
COM-TEAM
查看>>