'mews/captcha doesn't accept right answer (always need to reload the captcha to make it works)
I need to use math image captcha and mews/captcha is the best one I've seen so I implemented it. But I always need to reload the captcha first to login properly. Is this a bug and how to fix this without modifying vendor directory?
login.blade.php
<div class="form-group row">
<label for="captcha" class="col-md-3 col-form-label text-md-right">Captcha</label>
<div class="col-md-6 captcha">
<span>{!! captcha_img() !!}</span>
<button type="button" class="btn btn-danger" class="reload" id="reload">
↻
</button>
</div>
</div>
<div class="form-group row">
<label for="captcha" class="col-md-3 col-form-label text-md-right">Enter Captcha</label>
<div class="col-md-6">
<input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
</div>
</div>
<div class="form-group account-btn text-center m-t-10">
<div class="col-xs-12">
<button class="btn w-lg btn-primary waves-effect waves-light" type="submit">Sign In</button>
</div>
</div>
<script type="text/javascript">
$('#reload').click(function () {
$.ajax({
type: 'GET',
url: 'reload-captcha',
success: function (data) {
$(".captcha span").html(data.captcha);
}
});
});
</script>
LoginController.php
public function reloadCaptcha()
{
return response()->json(['captcha'=> captcha_img()]);
}
public function loginAction(Request $request){
$validator = \Validator::make($request->all(), [
'email' => 'required',
'password' => 'required',
'captcha' => 'required|captcha',
]);
if ($validator->fails()){
$data = $validator->getMessageBag()->toArray();
return Tools::jsonResponse('error', 'Mohon perbaiki data pada formulir yang diberikan', $data);
} else {
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
