I try to code in my Controller the Login page for 2 differant users. One they have 2FA enabled the other not.
$request
=User:
Value 1= Disabled and ignore messagedecrypt
Value 2= 2FA Enabled and use redirect to page messagedecrypt
if ($request->twofactor== 1)
and
if ($request->twofactor == 2)
AuthController:
public function LoginPost(Request $request){
$rules = ['captcha' => 'required|captcha'];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
session()->flash('errormessage','Invalid captcha ');
return redirect()->back();
}
if ($request->username == null || $request->password == null) {
session()->flash('errormessage','You must populate all fields ');
return redirect()->back();
}
$user = User::where('username',$request->username)->first();
if ($user == null) {
session()->flash('errormessage','Invalid username ');
return redirect()->back();
}
if ($user->verified == false) {
session()->flash('errormessage','Your account is not verified ');
return redirect()->route('verify');
}
if (!Hash::check($request->password,$user->password) && !Hash::check($request->username,$user->username))
{
session()->flash('errormessage','Your Login Credential Are Wrong');
return redirect()->back();
}
else
{
session()->flash('user_name',$request->username);
session()->flash('user_password',$request->password);
return redirect('messagedecrypt');
}
}
No i have try to make it with if ($request->twofactor == ..)
Like this:
public function LoginPost(Request $request){
$rules = ['captcha' => 'required|captcha'];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
session()->flash('errormessage','Invalid captcha ');
return redirect()->back();
}
if ($request->username == null || $request->password == null) {
session()->flash('errormessage','You must populate all fields ');
return redirect()->back();
}
$user = User::where('username',$request->username)->first();
if ($user == null) {
session()->flash('errormessage','Invalid username ');
return redirect()->back();
}
if ($user->verified == false) {
session()->flash('errormessage','Your account is not verified ');
return redirect()->route('verify');
}
if ($request->twofactor== 2){
if (!Hash::check($request->password,$user->password) && !Hash::check($request->username,$user->username))
{
session()->flash('errormessage','Your Login Credential Are Wrong');
return redirect()->back();
}
else
{
session()->flash('user_name',$request->username);
session()->flash('user_password',$request->password);
return redirect('messagedecrypt');
}
}
if ($request->twofactor== 1){
if (Auth::attempt(['username' => $request->username, 'password' => $request->password])) {
$user = Auth::user();
$user->last_seen = date('Y-m-d H:i:s', time());
$user->save();
return redirect()->route('home');
} else {
session()->flash('errormessage','Invalid password ');
return redirect()->back();
}
}
}
But get only an blank page. Whats the Problem?
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire