60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\User;
|
|
|
|
class CustomLoginController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('auth.login');
|
|
}
|
|
public function post_login(Request $request)
|
|
{
|
|
Validator::make($request->all(), [
|
|
'email' => 'required|email',
|
|
'password' => 'required',
|
|
])->validate();
|
|
|
|
$credentials = array('email' => $request->email, 'password' => $request->password);
|
|
|
|
$user = User::where('email', $credentials['email'])->first();
|
|
|
|
if ($user && Hash::check($credentials['password'], $user->password)) {
|
|
Auth::attempt(['email' => $request->email, 'password' => $request->password]);
|
|
|
|
return redirect('dashboard')->with([
|
|
'message' => trans('Selamat datang kembali'),
|
|
'type' => "success"
|
|
]);
|
|
|
|
}else{
|
|
return redirect('/login')
|
|
->withInput()
|
|
->with([
|
|
'message' => trans('Akun anda tidak ditemukan'),
|
|
'type' => "error"
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
Auth::logout();
|
|
return redirect('/login')
|
|
->withInput()
|
|
->with([
|
|
'message' => trans('Berhasil Keluar'),
|
|
'type' => "success"
|
|
]);
|
|
|
|
}
|
|
}
|