[英]How do I authenticate a user in Laravel 8 Jetstream only if his status is active?
I am building a Laravel 8 application and have successfully implemented authentication.我正在构建一个 Laravel 8 应用程序并已成功实现身份验证。 Now I want to check if a user's status is active before logging him in. I have added a field in the users table
现在我想在登录之前检查用户的状态是否处于活动状态。我在用户表中添加了一个字段
username varchar
password varchar
....
status tinyint(1)
...
I am using JetStream and Fortify我正在使用JetStream和Fortify
Thank You谢谢
I am building a Laravel 8 application and have successfully implemented authentication.我正在构建Laravel 8应用程序,并已成功实现身份验证。 Now I want to check if a user's status is active before logging him in. I have added a field in the users table
现在,我想在登录之前检查用户的状态是否为活动状态。我在users表中添加了一个字段
username varchar
password varchar
....
status tinyint(1)
...
I am using JetStream and Fortify我正在使用JetStream和Fortify
Thank You谢谢你
This is with a custom error message.这是带有自定义错误消息的。
Fortify::authenticateUsing(function (Request $request) {
$user = User::where('email', $request->email)->first();
if ($user && Hash::check($request->password, $user->password)) {
if ($user->active == 1) { // it will return if status == 1
return $user;
}
throw ValidationException::withMessages(['Your Message Here!']);
}
});
I am building a Laravel 8 application and have successfully implemented authentication.我正在构建Laravel 8应用程序,并已成功实现身份验证。 Now I want to check if a user's status is active before logging him in. I have added a field in the users table
现在,我想在登录之前检查用户的状态是否为活动状态。我在users表中添加了一个字段
username varchar
password varchar
....
status tinyint(1)
...
I am using JetStream and Fortify我正在使用JetStream和Fortify
Thank You谢谢你
您也应该添加:使用 Illuminate\\Support\\Facades\\Hash;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.