管理员未在多重身份验证中注销

时间:2018-02-16 11:44:31

标签: php authentication laravel-5

我正在尝试为管理员和用户进行多重身份验证。 用户登录并注销没有任何问题。

  

但管理员已登录但未注销。我需要加倍吗?   退出功能或我错误。

AdminLoginController.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class AdminLoginController extends Controller
{
    public function __construct()
    {
          $this->middleware('guest:admin', ['except' => 'logout']);
    }

    public function showLoginForm(){
        return view('auth.admin-login');
    }

    public function login(Request $request)
    {
        //Validate the form data
        $this->validate($request,[
            'email' => 'required|email',
            'password' => 'required|min:6'
        ]);

        //Attempt to log th user in
        if (Auth::guard('admin')->attempt(['email' => $request->email,'password' => $request->password],$request->remember)){
            //if successful, then redirects to their intended location
            return redirect()->intended(route('admin.dashboard'));
        }
//        if unsuccessful, then redirect back to thee login with the form data
        return redirect()->back()->withInput($request->only('email','remember'));
    }
}

登录Controller.php

<?php

namespace App\Http\Controllers\Auth;

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

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = '/';

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

    public function logout(Request $request) {
        Auth::logout();
        return redirect('/');
    }

}

0 个答案:

没有答案