75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Providers\RouteServiceProvider;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class LoginController extends Controller
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Login Controller
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This controller handles authenticating users for the application and
|
|
| redirecting them to your home screen. The controller uses a trait
|
|
| to conveniently provide its functionality to your applications.
|
|
|
|
|
*/
|
|
|
|
use AuthenticatesUsers;
|
|
|
|
/**
|
|
* Where to redirect users after login.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $redirectTo = RouteServiceProvider::HOME;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('guest')->except('logout');
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
return view('auth.login');
|
|
}
|
|
|
|
public function authenticate(Request $request)
|
|
{
|
|
$request->validate([
|
|
'email' => 'required|string|email',
|
|
'password' => 'required|string',
|
|
]);
|
|
|
|
$credentials = $request->only('email', 'password');
|
|
|
|
if (Auth::attempt($credentials)) {
|
|
$auth_user = Auth::user();
|
|
$cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
|
|
return view('homepage.home',compact('cawangan_info'));
|
|
}
|
|
|
|
return redirect('login')->with('error', 'Oppes! You have entered invalid credentials');
|
|
}
|
|
|
|
public function logout(){
|
|
Auth::logout();
|
|
Session::flush();
|
|
return Redirect::to('/');
|
|
}
|
|
}
|