如何防止用户在没有邮件确认的情况下登录?
数据库集正确。当用户通过单击收到的消息中的链接确认注册时,值"已确认"将从 0(默认值)更改为 1。当然是布尔类型。我需要"else if"语句才能工作,但我无法弄清楚如何工作。这是我的代码:
public function postSignin(Request $request)
{
$this->validate($request, [
'email' => 'required',
'password' => 'required'
]);
if (!Auth::attempt($request->only(['email', 'password']),
$request->has('remember')))
{
return redirect()->back()->with(notify()->flash("Ooops..", "error", [
'timer' => 5000,
'text' => 'Could not sign in with those details',
]));
}
else if ((Auth::attempt($request->only(['email', 'password'])))&&('confirmed'===0))
{
return redirect()->back()->with(notify()->flash("Ooops..", "error", [
'timer' => 5000,
'text' => 'Activate your account',
]));
}
else
{
return redirect()->route('home');
}
}
public function postSignin(Request $request)
{
$this->validate($request, [
'email' => 'required',
'password' => 'required'
]);
// This line will always log the user **in** if the account is confirmed or not.
if (!Auth::attempt($request->only(['email', 'password']),
$request->has('remember')))
{
return redirect()->back()->with(notify()->flash("Ooops..", "error", [
'timer' => 5000,
'text' => 'Could not sign in with those details',
]));
}
else if (!Auth::attempt(["email"=>$request->input("email"),"password"=>$request->input('password'),"confirmation"=>1])
{
return redirect()->back()->with(notify()->flash("Ooops..", "error", [
'timer' => 5000,
'text' => 'Activate your account',
]));
}
else
{
return redirect()->route('home');
}
}