HI,我已经使用laravel身份验证实现了laravel登录模块。我使用Auth :: check对用户进行身份验证,并在Auth :: attempt方法中发送user_name,password。我在users表中有status列。
如何限制Auth :: check以仅验证状态为1的用户?
答案 0 :(得分:6)
只需将状态字段设置为确认之一即可。你可以这样做:
$credentials = array(
'username' => $input['email'],
'password' => $input['password'],
'status' => 1
);
if (Auth::attempt($credentials))
{
// User status is 1 and password was correct
}
如果您想明确告诉用户他们不活跃 - 您可以使用以下方式进行跟进:
if (Auth::validate(['username' => $input['email'], 'password' => $input['password'], 'status' => 0]))
{
return echo ('you are not active');
}
答案 1 :(得分:2)
您可以向Auth :: attempt方法添加其他条件
if (Auth::attempt(array('email' => $email, 'password' => $password, 'status' => 1)))
{
//user is logged in (email and password matched, status is 1)
}