order_gizi/app/Http/Controllers/AuthController.php
2026-05-12 15:22:23 +07:00

59 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Response;
class AuthController extends Controller
{
private int $loginDecaySeconds = 60;
private int $maxLoginAttempts = 10;
public function index(){
$data = [
'title' => 'Login Admin | Order Gizi'
];
return view('auth.index', $data);
}
public function authanticate(Request $request){
$validated = $request->validate([
'username' => 'required',
'password' => 'required',
'website' => 'nullable',
]);
if (trim((string) $request->input('website', '')) !== '') {
return back()->withInput($request->only('username'))
->with(['alertError' => 'Gagal Login!']);
}
$now = time();
$rateKey = 'login:' . $request->ip() . ':' . strtolower((string) $request->input('username'));
// IMPORTANT: only pass auth credentials to Auth::attempt
// (do not include captcha / honeypot fields, otherwise Laravel will query non-existent columns)
$credentials = [
'username' => (string) ($validated['username'] ?? ''),
'password' => (string) ($validated['password'] ?? ''),
];
if(Auth::attempt($credentials)){
$request->session()->regenerate();
return redirect()->intended('/dashboard');
}
return back()->with(['alertError' => 'Gagal Login!']);
}
public function logout()
{
Auth::logout();
request()->session()->invalidate();
request()->session()->regenerateToken();
return redirect('/login');
}
}