<?php

            include('../../config/config.php');
            
            
            
               // Set CORS headers to allow requests from any origin (*)
        header("Access-Control-Allow-Origin: *");
        
        // Allow specific HTTP methods
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
        
        // Allow specific HTTP headers
        header("Access-Control-Allow-Headers: Content-Type, Authorization");
        
        // Allow cookies to be included in the request (if needed)
        header("Access-Control-Allow-Credentials:true");
        
        // Retrieve the raw POST data
        
        
       
       
 
        
      
        $uname =  mysqli_real_escape_string($link, trim(isset($_POST['username']) ? $_POST['username'] : ''));
        $pword = mysqli_real_escape_string($link,trim(isset($_POST['password']) ? $_POST['password'] : ''));
        
          $hashedPassword = md5($pword);
          
          
           
          
          
      $sql = ("SELECT * FROM `userlogin` WHERE `UserName`='$uname' AND `Password` = '$hashedPassword'");
      $result = mysqli_query($link, $sql);
      $row = mysqli_fetch_assoc($result);
      $row_cnt = mysqli_num_rows($result);

      if ($row_cnt > 0) 
      {
          
          
           $UserID = $row['UserID'];
		   $UserType = $row['UserType'];
		   
		   
		   $response = array(
                "requestSuccessful" => true, // Assuming the request was successful
                "responseMessage" => "success",
                "responseDescription" => "Login successfull",
                "UserID" => $UserID,
                "UsertType" => $UserType
                 
            ); 

         

      }
      else
      {
          
               $response = array(
                "requestSuccessful" => true, // Assuming the request was successful
                "responseMessage" => "failed",
                "responseDescription" => "Invalid Login Details",
                "UserID" => 'NULL',
                "UsertType" => 'NULL'
                 
            ); 
            
           
				
      }
      
      
         $json_response = json_encode($response);
    
        // // Output the JSON response
        echo $json_response;
            
            
            
        
        



?>