Last active
June 26, 2019 22:04
-
-
Save ImtiazEpu/1bed6dd06cf6c22876e9b918eb199d1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//login method | |
public function processLogin() | |
{ | |
$validator = Validator::make(request()->all(), [ | |
'email' => 'required|email', | |
'password' => 'required', | |
]); | |
if ($validator->fails()) { | |
return redirect()->back()->withErrors($validator)->withInput(); | |
} | |
$credentials = request()->only(['email', 'password']); | |
if(auth()->attempt($credentials)) { | |
if (Auth::user()->hasAnyRole('admin')){ | |
alert()->success('Success', 'Admin logged in!')->toToast(); | |
return redirect('/dashboard'); | |
} else { | |
if (auth()->user()->email_verified_at === null) { | |
auth()->logout(); | |
alert()->warning('Pending', 'Your account is not activated!')->toToast(); | |
return redirect()->route('login'); | |
} | |
} | |
alert()->success('Success', auth()->user()->name.' logged in!')->toToast(); | |
return redirect()->intended(); | |
} | |
alert()->error('Invalid credentials', 'Your Email or password was incorrect!'); | |
return redirect()->back(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment