我有Laravel代码登录auth页面,问题是当我登录非活动用户时,我应该收到错误消息,说明你的用户没有被激活。
我的代码
public function postLogin(Request $request)
{
$credentials = $request->only(['username', 'password']);
$validator = Validator::make($credentials, [
'username' => 'required', 'password' => 'required',
]);
// If the user is activated then value will be 1 and not activated user will 0
// <--- THIS LINE
if(!$credentials['active'] = 1)
{
return Redirect::back()->withInput()->withErrors($validator);
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
}
if (Auth::guard('admin')->attempt($credentials)) {
admin_toastr(trans('admin::lang.login_successful'));
return redirect()->intended(config('admin.prefix'));
}
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
答案 0 :(得分:0)
您在if语句中没有使用正确的运算符。变化
if(!$credentials['active'] = 1)
{
return Redirect::back()->withInput()->withErrors($validator);
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
到
if(!$credentials['active'] == 1)
{
return Redirect::back()->withInput()->withErrors($validator);
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
OR
if($credentials['active'] != 1)
{
return Redirect::back()->withInput()->withErrors($validator);
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}