2016-03-16 71 views
0

如何防止用戶在沒有郵件確認的情況下登錄?阻止沒有[激活具有「真實」值]的用戶登錄

數據庫設置正確。當用戶通過單擊收到的消息中的鏈接確認註冊時,值「確認」從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'); 
    } 
} 

回答

0
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'); 
} 
} 
+0

實際上,它顯示了激活您的帳號信息,但用戶登錄!我想防止登錄。 –

+0

無論「確認」值是真還是假,它仍然是正常的驗證。我很困惑 –

+0

不要只讀你的代碼。如果確認或不確認,第一行將始終記錄用戶。所以你可以把Auth :: logut()放入第一個和第二個if條件(一種破解)中。將更新我的答案。 – oseintow