How to check if user's status is active in laravel 5.x?

走远了吗. 提交于 2019-12-14 02:35:44

问题


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

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?

UPDATE: User Migration

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

回答1:


this is the correct way to do it : http://laravel.io/forum/11-04-2014-laravel-5-how-do-i-create-a-custom-auth-in-laravel-5?page=1#reply-29759

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



来源:https://stackoverflow.com/questions/34905258/how-to-check-if-users-status-is-active-in-laravel-5-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!