<?php

namespace App\Controllers;

use App\Models\Md_login;
$session = \Config\Services::session();

class Login extends BaseController
{
    
    
    public function __construct() {
         $this->Md_login = new Md_login();
    }
   
    public function AllLogin() 
    {
        header("Access-Control-Allow-Origin: *");
        // If you need to allow specific methods
        header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
        // If you need to allow specific headers
        header("Access-Control-Allow-Headers: Content-Type, Authorization");
        $datas = json_decode(file_get_contents("php://input"), true);
      
    
        $username=$datas['username'];
        $password=$datas['password'];
        $module=$datas['module'];
        
        $final = array();
        $ArrayData = array();
        
        if (!empty($username) && !empty($password) && !empty($module))
        {
            $userResult=$this->Md_login->loginUserVerify($username, md5($password), $module);
            
            if(empty($userResult))
            {
                
                $final = array('status' => 2,'result'=>'','msg'=>"Username or Confirm password is incorrect.");
            }else {
            $final = array('status' => 1,'result'=>$userResult, 'msg'=>"Your are login successfully.");
            }
        } else {
            $final = array('status' => 2,'result'=>'','msg'=>"Username or Confirm password is incorrect.");
        }
        echo json_encode($final);
        exit();
    }
}
