php - 表单提交后,两因素身份验证不返回错误消息
问题描述
我在我的 Laravel 5.8 项目中建立了一个 2FA 库。我想要做的只是当用户在 2FA 的刀片模板页面中键入两个因素身份验证代码时显示错误消息。我的代码块如下:
google2fa.php
<?php
return [
/*
* Auth container binding
*/
'enabled' => true,
/*
* Lifetime in minutes.
* In case you need your users to be asked for a new one time passwords from time to time.
*/
'lifetime' => 0, // 0 = eternal
/*
* Renew lifetime at every new request.
*/
'keep_alive' => true,
/*
* Auth container binding
*/
'auth' => 'auth',
/*
* 2FA verified session var
*/
'session_var' => 'google2fa',
/*
* One Time Password request input name
*/
'otp_input' => 'one_time_password',
/*
* One Time Password Window
*/
'window' => 1,
/*
* Forbid user to reuse One Time Passwords.
*/
'forbid_old_passwords' => false,
/*
* User's table column for google2fa secret
*/
'otp_secret_column' => 'google2fa_secret',
/*
* One Time Password View
*/
'view' => 'production.account.google2fa',
/*
* One Time Password error message
*/
'error_messages' => [
'wrong_otp' => "The 'One Time Password' typed was wrong.",
],
/*
* Throw exceptions or just fire events?
*/
'throw_exceptions' => true,
];
和我的 google2fa.blade.php 文件:
<!DOCTYPE html>
<html lang="en" class="website-html">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="csrf-token" content="{{ csrf_token() }}"/>
<title>{{$meta['title']}}</title>
<meta name="keywords" content="{{$meta['keywords']}}">
<meta name="description" content="{{$meta['description']}}">
<meta name="robots" content="{{$meta['robots']}}"/>
<meta property="og:url" content="{{$meta['canonical']}}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{$meta['title']}}" />
<meta property="og:description" content="{{$meta['description']}}" />
<meta property="og:image" content="{{$meta['image']}}" />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@{{env('APP_NAME')}}">
<meta name="twitter:creator" content="@{{env('APP_NAME')}}">
<meta name="twitter:title" content="{{$meta['title']}}">
<meta name="twitter:description" content="{{$meta['description']}}">
<meta name="twitter:image" content="{{$meta['image']}}">
<link rel="canonical" href="{{$meta['canonical']}}" />
</head>
<body>
<div class="page-wrapper">
<!-- Preloader -->
<div class="preloader"></div>
@include('production.common.alerts.flyin')
<!-- Header Style One -->
<header class="main-header header-style-one">
<!-- Header Upper -->
<div class="header-upper">
<div class="inner-container">
<div class="auto-container clearfix">
<!--Info-->
<div class="logo-outer">
<div class="logo"><a href="/"><img src="/colin/images/pci_logo_120_2.png?v={!!env('APP_STATIC_VERSION')!!}" alt="" title=""></a></div>
</div>
<!--Nav Box-->
<div class="nav-outer clearfix">
<!--Mobile Navigation Toggler-->
<div class="mobile-nav-toggler"><span class="icon flaticon-menu"></span></div>
<!-- Main Menu -->
<nav class="main-menu navbar-expand-md navbar-light">
<div class="navbar-header">
<!-- Togg le Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="icon flaticon-menu"></span>
</button>
</div>
<div class="collapse navbar-collapse clearfix" id="navbarSupportedContent">
<ul class="navigation clearfix">
<li class="@if( (isset($currentPage) and ($currentPage == '/') ) ) current @endif""><a href="/">Home</a></li>
<li class="dropdown @if( (isset($currentPage) and ($currentPage == 'solutions') ) ) current @endif"><a href="#">Solutions</a>
<ul>
<li><a href="/solutions/banking">Banking</a></li>
<li><a href="/solutions/e-commerce">E-Commerce</a></li>
<li><a href="/solutions/ssl-authorities">SSL Authorities</a></li>
</ul>
</li>
<li class="@if( (isset($currentPage) and ($currentPage == 'price') ) ) current @endif"><a href="/price">Pricing</a></li>
<li class="@if( (isset($currentPage) and ($currentPage == 'press') ) ) current @endif"><a href="/press">Press</a></li>
<li class="@if( (isset($currentPage) and ($currentPage == 'contact') ) ) current @endif"><a href="/contact">Contact</a></li>
</ul>
</div>
</nav>
<div class="option-box clearfix">
<div class="btn-box">
@if( isset($_session->id) )
<a href="/dashboard" class="theme-btn btn-style-one"><span class="txt">Go to Dashboard</span></a>
@else
<a href="/account/login" class="theme-btn btn-style-one"><span class="txt">Register/Login</span></a>
@endif
<a href="/free-demo" class="theme-btn btn-style-two"><span class="txt">Request A Demo</span></a>
</div>
</div>
</div>
</div>
</div>
</div>
<!--End Header Upper-->
<!-- Mobile Menu -->
<div class="mobile-menu">
<div class="menu-backdrop"></div>
<div class="close-btn"><span class="icon flaticon-plus"></span></div>
<nav class="menu-box">
<div class="nav-logo" style="max-width: 60%;"><a href="/"><img src="/colin/images/pci_logo_invert.png?v={!!env('APP_STATIC_VERSION')!!}" alt="" title=""></a></div>
<ul class="navigation clearfix"><!--Keep This Empty / Menu will come through Javascript--></ul>
</nav>
</div><!-- End Mobile Menu -->
</header>
<!-- End Main Header -->
<main>
<div class="container">
<div style="padding:80px 0 40px 0"> </div>
<form method="POST" action="{{ route('2fa') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="one_time_password" class="col-md-12 control-label">{{env('APP_NAME')}} - Two Factor Authentication</label>
</div>
<div class="form-group">
<input id="one_time_password" class="form-control" name="one_time_password" required autofocus>
</div>
<div class="form-group">
<label style="font-size:12px;">2FA has been enabled for your account! Please Use Code via Google Authenticator</label>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Continue
</button>
</div>
</div>
</form>
</div>
</main>
@include('layouts.production.site.footer')
</div>
<div class="scroll-to-top scroll-to-target" data-target="html"><span class="fa fa-angle-up"></span></div>
</body>
我不知道原因,但我在会话和 cookie 上都没有任何错误。任何帮助都会很好。
解决方案
只需使用默认的就足够了。
@if ($errors->any())
<div class="alert alert-danger">
{{ $errors->first('message') }}
</div>
@endif
将此代码段粘贴到您的代码中,它应该在验证代码时捕获第一条错误消息。
推荐阅读
- c# - 将 double[] 添加到 C# 中的自定义堆栈
- angular - 要使用的 Angular 组件
- wpf - 窗口标题下的黑线
- c# - 如何在 OData 中按今天过滤日期时间属性
- php - Symfony2.8->3.0:请求格式覆盖方法
- google-chrome-extension - 清单 v3 资源必须在 web_accessible_resources 中列出
- functional-programming - 证明两个函数的外延相等
- javascript - json 文件未更新 on.push()
- python - 应用聚类算法对相似的参与者进行分组
- dictionary - 有没有人成功地在函数上使用 python 的映射来计算缓冲区?