laravel authenticate redirect error

时间:2017-12-02 07:30:17

标签: php laravel redirect login laravel-5.4

问题是:

如果我打开浏览器(chrome)并将URL“localhost:8000”页面正常重定向到localhost:8000 / login。一切都好。如果我从浏览器更改URL,如localhost:8000 / e / login(此url是管理员保护段)页面转到管理员登录页面。

我填写用户名和密码区域,然后单击登录按钮,然后单击

页面应该转到localhost:8000 / e管理仪表板,但页面转到localhost:8000 /登录页面。

为什么?当我第一次打开浏览器并编写localhost:8000 url并将此url更改为localhost:8000 / e / login时出现此问题。其他组合很好但不是这个。

为什么?

  

这是管理员登录控制器

<?php

namespace App\Http\Controllers\X\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    use AuthenticatesUsers {
        logout as performLogout;
    }

    protected $redirectTo = '/e';
    private $continueURL = '';

    public function __construct(Request $request)
    {
        $this->middleware('guest:x')->except('logout');

        if ( $request->has('continue') )
            $this->continueURL = '/'.$request->input('continue');
    }

    public function showLoginForm()
    {
        return view('x.auth.login')->with('continueURL', $this->continueURL);
    }

    public function logout(Request $request)
    {
        $this->performLogout($request);
        return redirect()->route('x.login');
    }

    protected function authenticated(Request $request, $user)
    {
        if ( $request->has('continueURL') )
            return redirect($request->input('continueURL'));
    }

    protected function guard()
    {
        return \Auth::guard('x');
    }
}
  

这是网站的登录控制器

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = '/';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}
  

这是RedirectIfAuthenticated中间件

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    public function handle($request, Closure $next, $guard = null)
    {
        switch ($guard) {
            case 'x':
            if (Auth::guard('x')->check())
                return redirect()->route('x.dashboard');
            break;
            default:
            if (Auth::guard()->check())
                return redirect()->route('dashboard');
            break;
        }

        return $next($request);
    }
}
  

这是Exceptions / Handler.php

中的身份验证例外
protected function unauthenticated($request, AuthenticationException $exception)
{
    $guard = array_get($exception->guards(), 0);

    if ($request->ajax() || $request->expectsJson()) {
        return response()->json(['error' => 'Üye Girişi Yapmadınız'], 401);
    }

    if ( $guard == 'x' ){
        return redirect()->guest(route('x.login'));
    }

    return redirect()->guest(route('login'));
}
  

这是routes.php

<?php

Route::group(['prefix' => 'e', 'as' => 'x.', 'namespace' => 'X'], function() {

    $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
    $this->post('login', 'Auth\LoginController@login');
    $this->post('logout', 'Auth\LoginController@logout')->name('logout');

    $this->group(['middleware' => ['auth:x']], function(){

        $this->get('/', 'EvalutionController@dashboard')->name('dashboard');
        $this->get('/setting', 'SettingController@index')->name('setting');

        $this->group(['prefix' => 'evalution', 'as' => 'evalution.'], function(){
            $this->get('/', 'EvalutionController@allList')->name('list');
            $this->get('/{evalution_id}', 'EvalutionController@start')->name('start');
        });
    });
});

Auth::routes();

Route::group(['middleware' => 'auth'], function(){
    $this->get('/', 'HomeController@dashboard')->name('dashboard');
});
  

问题出在哪里?

0 个答案:

没有答案