在自定义Laravel中创建身份验证锁定屏幕

时间:2018-11-16 22:18:21

标签: php laravel

我在 Laravel 上实现了一个小型应用程序,否则用户将有可能在许多次后解锁其帐户,但是代码Call to a member function hasLockoutTime() on null 图像绑定较低

我的控制器

public function locked()
{
    if(!session('lock-expires-at')){
        return redirect()->route('admin');
    }

    if(session('lock-expires-at') > now()){
        return redirect()->route('admin');
    }

    return view('admin.auth.locked')
        ->with('success', 'Account Locked Successfully!');
}

public function unlock(Request $request)
{
    $check = Hash::check($request->input('password'), $request->user()->password);

    if(!$check){


    }

    session(['lock-expires-at' => now()->addMinutes($request->user()->getLockoutTime())]);

    alert()->success('Welcome','Welcome Back '.auth()->user()->name);
    return redirect()->route('admin');
}

我的中间件

   public function handle($request, Closure $next,$guard = null)
{

    if (!$request->user()->hasLockoutTime()) {
        // Check if previous session was set, if so, remove it because we don't need it here.
        if (session('lock-expires-at')) {
            session()->forget('lock-expires-at');
        }
        return $next($request);
    }
    if ($lockExpiresAt = session('lock-expires-at')) {
        if ($lockExpiresAt < now()) {
            return redirect()->route('admin.login_locked');
        }
    }
    session(['lock-expires-at' => now()->addMinutes($request->user()->getLockoutTime())]);

    return $next($request);
}

我的内核

 protected $routeMiddleware = [

    'auth.lock' => \App\Http\Middleware\AuthLock::class,
];

图片 enter image description here

0 个答案:

没有答案