<?php

namespace App\Http\Controllers\web\home;

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

class loginController extends Controller
{
    public function login(){
        return view('web.home.login.login');
    }

    public function user_login(Request $request){
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);

        $credentials = $request->only('email', 'password');
        $user = User::where('email', $request->email)->first();
      

        if ($user && $user->email_verified_at !== null && Auth::attempt($credentials) && $user->status ==1) {
            // Authentication successful
            return response()->json(['success' => true]);
        } else {
            // Authentication failed
            return response()->json(['success' => false], 401); // Unauthorized status code
        }
    }
}
