1

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

 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呢?

更新:用户迁移

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();
});
4

1 回答 1

1

这是正确的方法:http ://laravel.io/forum/11-04-2014-laravel-5-how-do-i-create-a-custom-auth-in-laravel-5?page =1#reply-29759

你的方法不起作用,因为 Laravel 默认的 Auth::attempt 不会检查 is_active 条件。

于 2016-01-21T15:46:57.110 回答