我遇到此身份验证时遇到问题,并特别确认了如何显示错误。这说“它处于活跃状态”。代码有效,用户无法登录,但没有错误。我该怎么做?
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(\Illuminate\Http\Request $request)
{
$credentials = $request->only($this->username(), 'password');
return array_add($credentials, 'active', '1');
}
答案 0 :(得分:1)
在 RegistersUsers 内部有一个功能
protected function registered(Request $request, $user)
{
if(!$user->active){
// store msg in session and display to user
Auth::logout();
}
}
类似地
AuthenticatesUsers 中的有一个功能
protected function authenticated(Request $request, $user)
{
if(!$user->active){
//store msg in session and display to user
Auth::logout();
}
}
答案 1 :(得分:0)
试试这样:
添加您的控制器类
use app\User;
CONTROLLER
protected function credentials(\Illuminate\Http\Request $request)
{
$credentials = $request->only($this->username(), 'password');
$user_active = User::where('username', $request->username)->first();
if ($user_active->active != 1){
return 'error';
}else{
return array_add($credentials, 'active', '1');
}
}
您可以为具有"有效"的用户插入验证= 1,如果尝试登录但未激活的用户则返回错误。请尝试一下,让我知道如果用户没有激活返回错误,如果它工作,我将更新我的问题与messagge错误"用户未激活"在视图中。