<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use App\Models\User;

class AuthController extends Controller
{
    public function loginForm()
    {
        return view('login'); // tu vista
    }

    public function login(Request $request)
    {
        $credenciales = [
            'username' => $request->username,
            'password' => $request->password
        ];

        if (Auth::attempt($credenciales)) {
            $request->session()->regenerate();

            return redirect('/dashboard');
            //return redirect()->route('dashboard');
        }

        return back()->with('error', 'Usuario o contraseña incorrectos');
    }

    public function logout(Request $request)
    {
        Auth::logout();
        $request->session()->invalidate();
        $request->session()->regenerateToken();
        return redirect('/login');
    }
}
