如何在laravel 5.x中检查用户状态是否处于活动状态? [英] How to check if user's status is active in laravel 5.x?

查看:87
本文介绍了如何在laravel 5.x中检查用户状态是否处于活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在laravel 5.2提供的AuthController中设置了一些不同的登录逻辑.代码是

I have set a bit different login logic in AuthController provided by laravel 5.2. The code is

 protected function authenticated(Request $request)
    {

        $email = $request->input('email');
        $password = $request->input('password');

        if (Auth::attempt(['email' => $email, 'password' => $password, 'is_active' => 1])) {
            return redirect()->intended('admin/dashboard');
        }

        return $this->sendFailedLoginResponse($request);
    }

代码工作正常.但是当用户不活跃时,该问题仍然以用户身份登录.那么如何停止使用is_active = 0对用户进行身份验证?

The code works fine. But the problem when user is not active, it still get logged in as users. So how do i stop authenticating users with is_active = 0?

更新:用户迁移

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password', 60);
    $table->tinyInteger('is_active', 0);
    $table->rememberToken();
    $table->timestamps();
});

推荐答案

这是正确的方法:您的方法无效,因为Laravel默认的Auth :: attempt不会检查is_active条件.

Your method won't work because the Laravel default Auth::attempt will not check the is_active condition.

这篇关于如何在laravel 5.x中检查用户状态是否处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆