如何为自定义防护覆盖authenticated()方法

时间:2019-03-11 20:59:25

标签: php laravel

当我想要覆盖authenticated()方法时,我有一个使用客户来自AuthenticateUser.php的特征的自定义守护程序,以便客户必须在登录该方法之前验证帐户未执行以尝试运行数据转储没有结果显示。因此,我想知道我是否必须进行路由web.php才能执行自定义防护措施,但不确定为什么未执行身份验证的方法。

logincontroller.php

<?php

namespace App\Http\Controllers\CustomerAuth;

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

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function guard()
    {
        return Auth::guard('customer');
    }

    public function logoutcustomer(Request $request)
    {
        $this->guard()->logout();
        $request->session()->invalidate();

        return redirect('/');
    }

    public function authenticated(Request $request, $customer)
    {
        if (!$customer->verified) {
            $this->guard()->logout();

            return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.');
        }

        return redirect()->intended($this->redirectPath());
    }

    public function showLoginForm()
    {
        if (Auth::user() || Auth::guard('customer')->user()) {
            return redirect('/');
        } else {
            return view('customer-auth.login');
        }
    }

    public function customerLogin(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|email',
            'password' => 'required|min:6',
        ]);

        if (Auth::guard('customer')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {

            return redirect()->intended('/');
        }

        return back()->withInput($request->only('email', 'remember'));
    }
}

0 个答案:

没有答案