的所有人。登录后我一直坚持使用Laravel重定向。连接工作,我登录后重定向到空白页面,但如果我更改网址路径,我可以访问不同的网页。任何帮助将非常感谢!我正在使用LDAP进行连接,它正在运行。
在我的AuthController上,我设置了受保护的$ redirectTo路径。见下图。
如果我还有其他代码,请告诉我。
谢谢!!!
(RedirectIfAuthenticated.php)
命名空间App \ Http \ Middleware;
使用Closure; 使用Illuminate \ Support \ Facades \ Auth;
class RedirectIfAuthenticated {
protected $auth;
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/computers/create');
}
return $next($request);
}
}
我的路线
Route::group(['middleware' => ['web']], function () {
Route::auth();
Route::get('login', 'LoginController@index');
Route::post('login', 'LoginController@check_password');
Route::patch('computers/{inventories}', 'InventoriesController@update');
Route::get('computers/search', 'InventoriesController@search');
Route::resource('computers', 'InventoriesController');
}); Route :: get('/ home','HomeController @ index');
loginController.php
<?php namespace App\Http\Controllers;
/**
* @class Login
*/
use App\User;
use Illuminate\Http\Request;
class Login extends Controller
{
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
return view('auth.login');
}
public function check_password(Request $req)
{
//die('has to stop here');
$user = User::check_password($req);
//var_dump($user); die;
if ($user)
{
return redirect('/computers/create');
}
else
{
return redirect('login')->with('message', 'Login Failed');
}
}
}
AuthController.php
<?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?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/computers/create';
protected $redirectAfterLogout = '/login';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
//$this->auth = $auth;
//$this->registrar = $registrar;
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
//Using Ldap
// protected function validator(array $data)
// {
// return Validator::make($data, [
// 'name' => 'required|max:255',
// 'email' => 'required|email|max:255|unique:users',
// 'password' => 'required|min:6|confirmed',
// ]);
//}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
//Removed b/c LDAP is being usedcd
// protected function create(array $data)
// {
// return User::create([
// 'name' => $data['name'],
// 'email' => $data['email'],
// 'password' => bcrypt($data['password']),
// ]);
// }
}
InventoriesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Inventory;
use App\Http\Requests\InventoryRequest;
class InventoriesController extends Controller
{
public function __construct()
{
//$this->middleware('auth'); //does not allow users to login, redirects back to login when using LDAP credentials
}
public function index(Request $request)
{
$location = $request->input("building");
if ($location != null) {
$inventories = Inventory::where('building', $location)->get();
} else {
$inventories = Inventory::all();
}
return view('computers.index', compact('inventories'));
}
public function show($inventories)
{
$inventories = Inventory::findOrFail($inventories);
return view::make('computers.show')
->with('inventory', $inventories);
}
public function create(){
//flash('Hello World', 'This is the message');
return view('computers.create');
}
/**
* Store a newly created resource in storage.
*
* @param inventory $request
* @return Response
*
*/
public function store(InventoryRequest $request)
{
Inventory::create($request->all());
flash('Success!', 'Inventory Successfully Updated!');
//s
// return redirect()->back(); //temporary
return back();
}
public function edit($inventories)
{
$inventories = Inventory::findOrFail($inventories);
return view('computers.edit', compact('inventories'));
}
public function update(InventoryRequest $request, Inventory $inventories){
$inventories->update($request->all());
flash('Success!', 'Inventory Successfully Updated!');
return back();
}
public function search()
{
$search = \Request::get('q'); //<-- we use global request to get the param of URI
// $search = Input::get('search');
$inventories = Inventory::where('lastName','LIKE','%'.$search.'%')
-> orwhere('firstName', 'LIKE','%'.$search.'%' )
-> orwhere('department', 'LIKE','%'.$search.'%' )
-> orwhere('building', 'LIKE','%'.$search.'%' )
-> orwhere('room', 'LIKE','%'.$search.'%' )
-> orwhere('manufacturer', 'LIKE','%'.$search.'%' )
-> orwhere('device', 'LIKE','%'.$search.'%' )
-> orwhere('model', 'LIKE','%'.$search.'%' )
-> orwhere('tag', 'LIKE','%'.$search.'%' )
-> orwhere('macAddress', 'LIKE','%'.$search.'%' )
-> orwhere('status', 'LIKE','%'.$search.'%' )
-> orwhere('comments', 'LIKE','%'.$search.'%' )
->get();
return view('computers.search',compact('inventories'));
}
}
答案 0 :(得分:1)
检查RedirectIfAuthenticated.php中间件。默认情况下它应该是这样的:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
}
确保返回的内容是好页面!!如果你没有那个中间件,可以看看Laravel的doc来创建一个!