
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NetPanel.Entity;
using NetPanel.Entity.Conf;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NetPanel.Help;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Text;
using NetPanel.Bl;

namespace NetPanel.Controllers.Login
{
    public class LoginController : MyController
    {
        public IActionResult Login()
        {
            return View();
        }



        public IActionResult GetUser()
        {


            //string output = ExecuteBl.Exec("ping www.baidu.com");


            //// 解析输出行
            //string[] lines = output.Split('\n');
            //string[] memoryInfo = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            //// 获取已使用和总内存大小
            //float totalMemory = float.Parse(memoryInfo[1]);
            //float usedMemory = float.Parse(memoryInfo[2]);

            //// 计算使用率
            //float usagePercentage = (usedMemory / totalMemory) * 100;

            ReturnMsg enReturnMsg = new ReturnMsg();
            enReturnMsg.Code = 0;
            enReturnMsg.Msg = "失败!";

            JObject json = GetJson();
            string name = json["UserName"].ToString("");
            string pwd = json["UserPwd"].ToString("");
            string sPath = AppContext.BaseDirectory;
            UserAdmin userAdmin = JsonConvert.DeserializeObject<UserAdmin>(System.IO.File.ReadAllText(sPath + "/Conf/UserAdmin.json"));
            if (userAdmin.UserName != name && userAdmin.UserPwd != pwd)
            {
                enReturnMsg.Msg = "用户名,密码错误!";
                return Json(enReturnMsg);
            }
            HttpContext.Session.SetString("user", JsonConvert.SerializeObject(userAdmin.UserName));

            enReturnMsg.Code = 1;
            enReturnMsg.Msg = "成功!";
            return Json(enReturnMsg);
        }
    }
}
