我在这里遇到了一个大问题我的应用程序运行顺利,直到有一天我的AUTH大楼不再工作了 . 它一直在告诉令牌不匹配错误,但当我尝试禁用CSRF时,登录总是会将我重定向回登录页面,如AUTH false . 有人可以帮助我,我在这里失踪了吗?我正在使用Laravel 5.2
route code:
Route::group(['middleware' => 'web'], function () {
Route::get('/login', 'Auth\AuthController@getLogin');
Route::post('/login', 'Auth\AuthController@postLogin');
Route::get('/home', 'AdminController@index');
});
kernal.php
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'auth' => [
\App\Http\Middleware\Authenticate::class,
],
'api' => [
'throttle:60,1',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
admincontroller
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Booking;
use App\Booktour;
use App\Bookcustomer;
use App\Bookdiscount;
use App\Booktourpay;
use App\Customerorder;
use App\Tourdetail;
use App\Tourperiod;
use App\Tourlead;
use Session;
use View;
use Carbon\Carbon;
use Auth;
use Datetime;
use DB;
use Image;
use App\User;
class AdminController extends Controller {
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$count_customer = Bookcustomer::count();
$getuser = Auth::user()->name;
$booking_order = Booking::where('sales_name', '=',$getuser)
->orderby('created_at', 'DSEC')
->get();
$booktour_open = DB::table('tourlist')->where('status' ,'=', 'เปิดขาย')->count();
$tour = Booktour::where('status', 'เปิดขาย')
->orderby('depart_date', 'asc')
->get();
$unpaid = Booking::where('sales_name', '=', $getuser)
->where('status', 'รอเงินโอน')
->count();
$allbook_list = Booking::where('status', '=', "รอเงินโอน")->orderby('created_at', 'DSEC')->get();
$today_date = strtotime('now');
$payment_list = Booktourpay::Today()->get();
$user_list_payment = Booktourpay::where('create_by', '=', $getuser)->get();
return view('admin.home')
->with('booking_order', $booking_order)
->with('count_customer', $count_customer)
->with('booktour_open', $booktour_open)
->with('tour', $tour)
->with('unpaid', $unpaid)
->with('allbook_list', $allbook_list)
->with('payment_list', $payment_list)
->with('user_list_payment', $user_list_payment);
}
authcontroller
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
protected $loginPath = '/login';
use AuthenticatesAndRegistersUsers;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
登录后我得到奇怪的重定向,无论用户/密码是否正确 .