session - TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1 -
when try login show me token error. have checked token in view form it's right , when comment \app\http\middleware\verifycsrftoken::class
, in kernel.php
makes me login after redirect dashboard i'm not logged in. using mamp on mac.
<div> <h1>login</h1> <div> {!! form::open(['url'=>'user/login','class' => '']) !!} <input type="hidden" name="_token" value="{{ csrf_token() }}"> <ul> <li><label>customer code</label>{!!form::text('customer_code',input::old('customer_code'),['class'=>''])!!}</li> <li><label>password</label>{!!form::password('password','',['class'=>''])!!}</li> <li>{!! form::submit('submit',array('class' => 'btn')) !!}</li> </ul> {!!form::close()!!} </div> <div><a href="{!!url::to('user/forget_password')!!}">forget password</a></div> </div>
meanwhile use sentry package
login.
/** * post_login */ public function post_login() { try { $rules = [ 'customer_code' => 'required', 'password' => 'required', ] ; $message = [ 'customer_code.required' => 'erorrr1', 'password.required' =>'error2' ]; $validator = validator::make(input::all(), $rules,$message); if ($validator->fails()) { return redirect::back()->witherrors($validator)->withinput(); } // if ($validator->fails()) else { $authuser = sentry::authenticateandremember(array( 'customer_code' => input::get('customer_code'), 'password' => input::get('password')), false); if($authuser) { //$login = sentry::loginandremember($authuser); return redirect::to('user/panel/'.$authuser->id)->with('comment', 'welcome'); } else { return redirect::back()->with('comment', 'error login'); } }//validator } catch(\exception $e) { return redirect::back()->withinput(input::except('password','file'))->witherrors(['error!!!!!']); } }
edited:
since using form builder remove form. laravel form builder automatically adds hidden token field form when form::open()
so remove line:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Comments
Post a Comment