75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\app\Http\Controllers\Auth;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Modules\AdminUser\app\Models\AdminUser;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function login()
|
|
{
|
|
if(Auth::check()){
|
|
return redirect()->route('dashboard');
|
|
}
|
|
|
|
return view('admin::auth.pages.login');
|
|
}
|
|
|
|
|
|
public function postLogin(Request $request){
|
|
try {
|
|
$rememberMe = $request->has('remember') ? true : false;
|
|
//-- Check if user email is valid
|
|
$adminUser = AdminUser::where('email', $request['email'])->first();
|
|
if (!$adminUser) {
|
|
toastr()->error('Incorrect Credential.');
|
|
return back();
|
|
}
|
|
//-- Validate Credentials
|
|
if (!Hash::check($request['password'], $adminUser->password)) {
|
|
toastr()->error('Incorrect Password.');
|
|
return back();
|
|
}
|
|
|
|
//-- Login User
|
|
Auth::login($adminUser, $rememberMe);
|
|
|
|
$request->session()->regenerate();
|
|
|
|
toastr()->success('You have successfully logged in');
|
|
|
|
return redirect()->route('dashboard');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
|
|
toastr()->error('Something went wrong.');
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
|
|
public function logout(Request $request)
|
|
{
|
|
//--log out process
|
|
Auth::logout();
|
|
|
|
$request->session()->invalidate();
|
|
$request->session()->regenerateToken();
|
|
|
|
toastr()->success('You have been logged out');
|
|
|
|
return redirect()->route("login");
|
|
}
|
|
|
|
|
|
}
|