<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\PropertyController;
use Illuminate\Support\Facades\Session;

class AuthController extends Controller

{
 public function login ()
 {
    if(!empty(Auth::check())){
        return redirect("landing");
    }
    // dd(Hash::make(value: 123));
    return view("auth.login");
 }    //

 public function auth_login(Request $request)
 {
     $remember = !empty($request->remember) ? true : false;
 
     // Attempt to authenticate the user
     if (Auth::attempt(['email' => $request->email, 'password' => $request->password], $remember)) {
         
         // Retrieve the authenticated user
         $user = Auth::user();
 
         // Store user details in the session
         Session::put('Name', $user->FullName);  // Assuming 'FullName' exists in the users table
         Session::put('RegNo', $user->UserCode); // Assuming 'UserCode' exists in the users table
 
         // Redirect to the landing page
         return redirect()->route('landing');
     } else {
         // Redirect back with an error message if authentication fails
         return redirect()->back()->with('error', 'Invalid Login');
     }
 }
 

public function logout (){
    Auth::logout();
    return redirect(url(''));
}
}