Closed youmikuang closed 7 years ago
我新建Request
测试了下,可以验证通过,下面是我的全部Request
代码,你对比看看
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'geetest_challenge' => 'required|geetest',
'geetest_validate' => 'required|geetest',
'geetest_seccode' => 'required|geetest',
];
}
/**
* 验证返回信息
*
* @return array
*/
public function messages()
{
return [
'geetest' => config('laravel-geetest.client_fail_alert')
];
}
}
如果使用的是Laravel
自带的认证登录,需要在Auth/LoginController.php
中覆盖AuthenticatesUsers
的Login
方法,修改Request
参数为自己的Request
.
/**
* Handle a login request to the application.
*
* @param LoginRequest $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
public function login(LoginRequest $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
@jormin 代码没改任何地方,上午一直提示服务端未通过验证。。估计是极验服务器的事吧。。
[Vue warn]: Error compiling template:
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Branding Image -->
<a class="navbar-brand" href="http://micro_web.dev/backend">
Aitifen Micro Web
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
</ul>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
<li><a href="javascript:void(0)">请先登录</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">后台页面登陆</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="http://micro_web.dev/backend/login">
<input type="hidden" name="_token" value="g7VuM0uPphkTLAnPlfQcnfwqxYE6l0RVhtdzBS0B">
<div class="form-group">
<label for="name" class="col-md-4 control-label">用户名/手机号</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="" required="" autofocus="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label"></label>
<div class="col-md-6">
<div id="embed-captcha"></div>
<p id="wait" class="show">正在加载验证码......</p>
<p id="notice" class="hide">请完成验证码</p>
<script src="/vendor/laravel-geetest/jquery.min.js"></script>
<script src="/vendor/laravel-geetest/gt.js"></script>
<script>
var handlerEmbed = function (captchaObj) {
$("#embed-submit").click(function (e) {
var validate = captchaObj.getValidate();
if (!validate) {
$("#notice")[0].className = "show";
setTimeout(function () {
$("#notice")[0].className = "hide";
}, 2000);
e.preventDefault();
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj.appendTo("#embed-captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
});
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: "http://micro_web.dev/geetest?uWzqTxX4Ht", // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
// 使用initGeetest接口
// 参数1:配置参数
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
new_captcha: data.new_captcha,
lang: 'zh-cn',
width: '300px',
product: 'popup', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerEmbed);
}
});
</script>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
(found in <Root>)
这个是什么错误。表示不明觉厉
去掉极验的东西就不报错。。。laravel5.3
是重复引入jQuery了吧
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
错误已经说明了,Vue
不解析<script>
标签,你把脚本代码分离出去试试。
@jormin 恩 好的
我用php artisan make:request AdminLoginRequest,然后我在request内部怎么使用geetest的验证呢???
补充: 加入geetest提示服务端验证错误
public function rules() { return [ 'name' => 'required', 'password' => 'required|min:6', 'geetest_challenge' => 'required|geetest', 'geetest_validate' => 'required|geetest', 'geetest_seccode' => 'required|geetest', ]; }