123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Ant.Service.Common;
- using System.Collections;
- using System.Xml;
- using MES.Production.Service;
- using System.Net;
- using Ant.Service.Utility;
- using MES.Production.Entity;
- using Ant.ORM;
- using Ant.Data;
- using System.Runtime.InteropServices;
- using System.Management;
- using System.Text;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- /// <summary>
- /// 登录控制器
- /// add 作者: 季健国 QQ:181589805 by 2016-05-22
- /// </summary>
- public class AccountController : Controller
- {
- [DllImport("Iphlpapi.dll")]
- private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
- [DllImport("Ws2_32.dll")]
- private static extern Int32 inet_addr(string ip);
- #region 声明容器
- MES.Production.Service.IService.IUserManage UserManage { get; set; }
- MES.Production.Service.IService.ISystemManage SystemManage { get; set; }
- string backurl = string.Empty;
- log4net.Ext.IExtLog log = log4net.Ext.ExtLogManager.GetLogger("dblog");
- #endregion
- /// <summary>
- /// 初始视图
- /// add 作者: 季健国 QQ:181589805 by 2016-05-10
- /// </summary>
- public ActionResult Index()
- {
- //移除Session
- SessionHelper.Remove("CurrentUser");
- CookieHelper.ClearCookie("cookie_rememberme");
- //try
- //{
- // IPAddress ipAddr = Dns.Resolve(Dns.GetHostName()).AddressList[1];//获得当前IP地址
- // string ip = ipAddr.ToString();
- // string userip = Request.UserHostAddress;
- // string strClientIP = Request.UserHostAddress.ToString().Trim();
- // Int32 ldest = inet_addr(ip); //目的地的ip
- // Int64 macinfo = new Int64();
- // Int32 len = 6;
- // int res = SendARP(ldest, 0, ref macinfo, ref len);
- // string mac_src = macinfo.ToString("X");
- // if (mac_src == "0")
- // {
- // if (userip == "127.0.0.1")
- // {
- // Response.Write("正在访问Localhost!");
- // }
- // else
- // {
- // // Response.Write("欢迎来自IP为" + userip + "的朋友!" + "<br>");
- // }
- // }
- // while (mac_src.Length < 12)
- // {
- // mac_src = mac_src.Insert(0, "0");
- // }
- // string mac_dest = "";
- // for (int i = 0; i < 11; i++)
- // {
- // if (0 == (i % 2))
- // {
- // if (i == 10)
- // {
- // mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
- // }
- // else
- // {
- // mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
- // }
- // }
- // }
- // Response.Write("欢迎来自IP为" + userip + "<br>" + ",MAC地址为" + mac_dest + "的朋友!" + "<br>");
- //}
- //catch (Exception err)
- //{
- // Response.Write(err.Message);
- //}
- return View();
- }
- ///<summary>
- /// SendArp获取MAC地址
- ///</summary>
- ///<param name="RemoteIP">目标机器的IP地址如(192.168.1.1)</param>
- ///<returns>目标机器的mac 地址</returns>
- public static string GetMacAddress(string RemoteIP)
- {
- StringBuilder macAddress = new StringBuilder();
- try
- {
- Int32 remote = inet_addr(RemoteIP);
- Int64 macInfo = new Int64();
- Int32 length = 6;
- SendARP(remote, 0, ref macInfo, ref length);
- string temp = Convert.ToString(macInfo, 16).PadLeft(12, '0').ToUpper();
- int x = 12;
- for (int i = 0; i < 6; i++)
- {
- if (i == 5)
- {
- macAddress.Append(temp.Substring(x - 2, 2));
- }
- else
- {
- macAddress.Append(temp.Substring(x - 2, 2) + "-");
- }
- x -= 2;
- }
- return macAddress.ToString();
- }
- catch
- {
- return macAddress.ToString();
- }
- }
- /// <summary>
- /// 获取网卡地址信息
- /// </summary>
- /// <returns></returns>
- string GetMacAddress()
- {
- try
- {
- string mac = "";
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection moc = mc.GetInstances();
- foreach (ManagementObject mo in moc)
- {
- if ((bool)mo["IPEnabled"] == true)
- {
- mac = mo["MacAddress"].ToString();
- break;
- }
- }
- moc = null;
- mc = null;
- return mac;
- }
- catch
- {
- return "unknow";
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public JsonResult getVehicleTrajectory()
- {
- string strjson = "";
- string start = Request.QueryString["start"];
- string end = Request.QueryString["end"];
- string carid = Request.QueryString["carid"];
- ResponseTrajectory mod = new ResponseTrajectory();
- mod.result = new List<Lnglat>();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
- };
- var q = orm.Queryable<Ent_YW_DrivingTrack>();
- if (!carid.IsEmpty())
- {
- q = q.Where(p => p.TripID == carid);
- }
- if (!start.IsEmpty() && !end.IsEmpty())
- {
- DateTime startDate = start.ToDateTime();
- DateTime endDate = end.ToDateTime();
- q = q.Where(p => p.Add_Time >= startDate && p.Add_Time <= endDate);
- }
- var count = q.Count();
- if (count > 1000)
- {
- q = q.Top(500);
- }
- var reslut = q.OrderBy(p => p.Add_Time).ToList(res);
- if (reslut.IsSuccess)
- {
- foreach (Ent_YW_DrivingTrack beatenty in reslut.ResultModel)
- {
- mod.imei = beatenty.IMEI;
- var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(beatenty.Lng.ToDou(), beatenty.Lat.ToDou());
- Lnglat enty = new Lnglat();
- enty.lng = GPS.Split(',')[0];
- enty.lat = GPS.Split(',')[1];
- enty.taskTime = beatenty.Add_Time.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
- mod.result.Add(enty);
- }
- mod.status = (mod.result.Count > 0) ? "1" : "0";
- }
- }
- return Json(mod, JsonRequestBehavior.AllowGet);
- }
- /// <summary>
- /// 登录验证
- /// add 作者: 季健国 QQ:181589805 by 2016-05-10
- /// </summary>
- public ActionResult login(Account item)
- {
- var json = new JsonHelper() { Msg = "登录成功", Status = "n", ReUrl = "/Sys/Home/Index" };
- try
- {
- var code = Request.Form["code"];
- var rememberme = Request.Form["remember"];
- if (Session["gif"] != null)
- {
- //if (!string.IsNullOrEmpty(code) && code.ToLower() == Session["gif"].ToString().ToLower())
- if (!string.IsNullOrEmpty(code))
- {
- var pwd = PasswordUtils.MD5_Encrypt(item.PassWord.Trim(), 32);// Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(item.PassWord.Trim())
- string userip = Request.UserHostAddress;
- var users = UserManage.UserLogin(item.LogName.Trim(), pwd);
- if (users != null)
- {
- //if (item.LogName == "admin" && Utils.GetIP() != "218.93.67.45")
- //{
- // json.Msg = "用户已锁定,禁止登录,需要进行解锁才能登录";
- // log.Warn(Utils.GetIP(), users.NAME, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- // return Json(json);
- //}
- if (users.USERTYPE == 0)
- {
- if (users.DPTID != null)
- {
- using (AntORM orm = new AntORM())
- {
- try
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询教练的单个实体方法" },
- Oid = users.DPTID.ToString()
- };
- var reslut = orm.GetEntity<YM_School>(request);
- if (reslut.IsSuccess)
- {
- var mod = (YM_School)reslut.ResultModel;
- if (mod.Status == 2 || mod.Status == 3)
- {
- json.Msg = "帐号已锁定,禁止登录,请联系管理员进行解锁";
- log.Warn(Utils.GetIP(), users.NAME, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- return Json(json);
- }
- }
- }
- catch (Exception e)
- {
- }
- }
- }
- }
- if (users.ISCANLOGIN == true)
- {
- json.Msg = "用户已锁定,禁止登录,请联系管理员进行解锁";
- log.Warn(Utils.GetIP(), users.NAME, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- return Json(json);
- }
- var acconut = this.UserManage.GetAccountByUser(users);
- //写入Session 当前登录用户
- SessionHelper.SetSession("CurrentUser", acconut);
- //默认记住我
- string cookievalue = "{\"id\":\"" + acconut.Id + "\",\"username\":\"" + acconut.LogName +
- "\",\"password\":\"" + acconut.PassWord + "\",\"ToKen\":\"" +
- Session.SessionID + "\"}";
- CookieHelper.SetCookie("cookie_rememberme", Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(cookievalue),
- null);
- json.Status = "y";
- log.Info(Utils.GetIP(), users.NAME, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- }
- else
- {
- json.Msg = "用户名或密码不正确";
- log.Error(Utils.GetIP(), item.LogName, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- }
- }
- else
- {
- json.Msg = "验证码不正确";
- log.Error(Utils.GetIP(), item.LogName, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- }
- }
- else
- {
- json.Msg = "验证码已过期,请刷新验证码";
- log.Error(Utils.GetIP(), item.LogName, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- }
- }
- catch (Exception e)
- {
- json.Msg = e.Message;
- log.Fatal(Utils.GetIP(), item.LogName, Request.Url.ToString(), "Login", "系统登录,登录结果:" + json.Msg);
- }
- return Json(json, JsonRequestBehavior.AllowGet);
- }
-
- /// <summary>
- /// 验证是否有登录权限
- /// </summary>
- public bool ValidateLogin(HttpRequestBase Request, out string backurl)
- {
- //获取返回页面
- backurl = Request["backurl"];
- string param = Request["para"];
- try
- {
- if (!string.IsNullOrEmpty(backurl))
- {
- if (!string.IsNullOrEmpty(param))
- {
- //解密
- param = Ant.Service.Common.CryptHelper.DESCrypt.Decrypt(param);
- if (!string.IsNullOrEmpty(param) && param.IndexOf('=') > 0 && param.ToLower().Contains("siteid"))
- {
- var siteId = param.Split('=')[1];
- //判断来源站点ID
- if (this.SystemManage.IsExist(p => p.ID == siteId))
- {
- return true;
- }
- else
- {
- log.Warn(Utils.GetIP(), "其他系统访问者", backurl, "Login", "其他系统登录失败,原因:来源站点不可信,系统拒绝登录");
- }
- }
- else
- {
- log.Warn(Utils.GetIP(), "其他系统访问者", backurl, "Login", "其他系统登录失败,原因:系统验证参数错误,系统拒绝登录");
- }
- }
- else
- {
- log.Warn(Utils.GetIP(), "其他系统访问者", backurl, "Login", "其他系统登录失败,原因:未传递系统验证参数,系统拒绝登录");
- }
- }
- }
- catch (Exception e)
- {
- log.Warn(Utils.GetIP(), "其他系统访问者", "", "Login", "其他系统登录失败,系统错误", e);
- }
- return false;
- }
- /// <summary>
- /// 验证码
- /// </summary>
- public FileContentResult ValidateCode()
- {
- string code = "";
- System.IO.MemoryStream ms = new ChangFaModels.verify_code().Create(out code);
- Session["gif"] = code;//验证码存储在Session中,供验证。
- Response.ClearContent();//清空输出流
- return File(ms.ToArray(), @"image/png");
- }
- }
- }
|