地铁二期项目正式开始

DefaultController.cs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Net.NetworkInformation;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. using YTSoft.BaseCallCenter.Model;
  12. using YTSoft.BaseCallCenter.MVCWeb.Models;
  13. using YTSoft.Common;
  14. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  15. {
  16. public class DefaultController : Controller
  17. {
  18. BLL.T_Sys_UserAccount busUserInfo = new BLL.T_Sys_UserAccount();
  19. public ActionResult Login()
  20. {
  21. T_Sys_UserAccount userInfo = new T_Sys_UserAccount();
  22. HttpCookie cookies = Request.Cookies["platform"];
  23. //判断是否有cookie值,有的话就读取出来
  24. if (cookies != null && cookies.HasKeys)
  25. {
  26. userInfo.F_UserName = cookies["Name"];
  27. }
  28. userInfo.ExtensionCode = ConfigurationManager.AppSettings["sso"].ToMyString();
  29. // userInfo.F_UserName = SystemInfo.GetCpuPerformancevalue();
  30. return View(userInfo);
  31. }
  32. [AcceptVerbs(HttpVerbs.Post)]
  33. public string LoginIn(string username, string extensionphone, string password)
  34. {
  35. string res = "未知错误,请重新登录";
  36. DataTable dt = new DataTable();
  37. try
  38. {
  39. dt = busUserInfo.GetList(username, password).Tables[0];
  40. if (dt != null)
  41. {
  42. if (dt.Rows.Count > 0)
  43. {
  44. if (dt.Rows[0]["F_UserCode"].ToString() == dt.Rows[0]["F_PassWord"].ToString())
  45. {
  46. res = "firstlogin" + dt.Rows[0]["F_UserId"].ToString();
  47. }
  48. else
  49. {
  50. //记住用户名每3个月更换一次
  51. HttpCookie cookie = new HttpCookie("platform");
  52. cookie.Values.Add("Name", username);
  53. cookie.Values.Add("islocal", "1");
  54. cookie.Expires = System.DateTime.Now.AddMonths(3);
  55. Response.Cookies.Add(cookie);
  56. if (!string.IsNullOrEmpty(extensionphone))
  57. {
  58. }
  59. else if (string.IsNullOrEmpty(dt.Rows[0]["F_ExtensionNumber"].ToMyString()))
  60. {
  61. extensionphone = dt.Rows[0]["ExtensionCode"].ToMyString();
  62. }
  63. else
  64. {
  65. extensionphone = dt.Rows[0]["F_ExtensionNumber"].ToMyString();
  66. }
  67. int tempExtensionphone = GetNetworkAdpaterID();
  68. if (tempExtensionphone > 0)
  69. {
  70. extensionphone = tempExtensionphone.ToMyString();
  71. }
  72. LogHelper.Default.WriteInfo("tsKey:" + extensionphone);
  73. Dictionary<string, string> Dic = new Dictionary<string, string>();
  74. Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString());
  75. Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString());
  76. Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
  77. Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToString(), Encoding.UTF8));
  78. Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
  79. Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
  80. Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
  81. Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToString());
  82. if (dt.Rows[0]["F_GroupId"].ToString() != null)
  83. {
  84. Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
  85. }
  86. if (dt.Rows[0]["F_SeatRight"].ToString() != null)
  87. {
  88. Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
  89. }
  90. Dic.Add("F_ExtensionNumber", extensionphone);
  91. Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
  92. CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
  93. //写入登录日志
  94. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  95. {
  96. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  97. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  98. F_Result = "登录成功",
  99. F_LoginIP = Common.DTRequest.GetIP(),
  100. F_Hostname = Common.DTRequest.GetIP(),
  101. F_LoginDate = DateTime.Now,
  102. F_Remark = "",
  103. F_State = 0
  104. });
  105. Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  106. Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();//Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  107. res = "success";
  108. //绑定登录用户分机号
  109. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  110. bll.UpdateWXId("ExtensionCode",extensionphone.ToInt32(), Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); }
  111. }
  112. else
  113. {
  114. //写入登录日志
  115. DataTable dt1 = busUserInfo.GetList("F_UserCode='" + username + "'").Tables[0];
  116. if (dt1.Rows.Count > 0)
  117. {
  118. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  119. {
  120. F_LoginName = dt1.Rows[0]["F_UserName"].ToString(),
  121. F_LoginId = Convert.ToInt32(dt1.Rows[0]["F_UserId"].ToString()),
  122. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  123. F_LoginIP = Common.DTRequest.GetIP(),
  124. F_Hostname = Common.DTRequest.GetIP(),
  125. F_LoginDate = DateTime.Now,
  126. F_Remark = "",
  127. F_State = 0
  128. });
  129. }
  130. else
  131. {
  132. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  133. {
  134. F_LoginName = username,
  135. F_LoginId = -1,
  136. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  137. F_LoginIP = Common.DTRequest.GetIP(),
  138. F_Hostname = Common.DTRequest.GetIP(),
  139. F_LoginDate = DateTime.Now,
  140. F_Remark = "",
  141. F_State = 0
  142. });
  143. }
  144. res = "账号或密码错误,请重新登录";
  145. }
  146. }
  147. else
  148. {
  149. res = "账号或密码错误,请重新登录";
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. res = "错误:" + ex.ToString();
  155. SysLog.WriteLog(ex);
  156. }
  157. finally
  158. {
  159. dt.Clear();
  160. dt.Dispose();
  161. }
  162. return res;
  163. }
  164. //退出系统
  165. [AcceptVerbs(HttpVerbs.Post)]
  166. public string LoginOut(string username)
  167. {
  168. string res = "未知错误,请重新登录";
  169. DataTable dt = new DataTable();
  170. try {
  171. string userid = Request.Cookies["BaseCallCenter_T_User"]["F_UserId"];
  172. dt = busUserInfo.GetList("F_UserId='" + userid + "'").Tables[0];
  173. //写入登录日志
  174. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  175. {
  176. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  177. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  178. F_Result = "退出系统成功",
  179. F_LoginIP = Common.DTRequest.GetIP(),
  180. F_Hostname = Common.DTRequest.GetIP(),
  181. F_LoginDate = DateTime.Now,
  182. F_Remark = "",
  183. F_State = 0
  184. });
  185. res = "success";
  186. //绑定登录用户分机号
  187. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  188. bll.UpdateWXId("ExtensionCode", 0, Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()));
  189. }
  190. catch(Exception){ }
  191. return res;
  192. }
  193. public ActionResult SSO()
  194. {
  195. bool res = false; //标记是否登录
  196. string LoginName=Request.Headers.Get("OAM_REMOTE_USER");
  197. LogHelper.Default.WriteInfo("LoginName:" + LoginName.ToMyString());
  198. if (!string.IsNullOrEmpty(LoginName))
  199. {
  200. if (!"Anonymous".Equals(LoginName))
  201. {
  202. res = true;
  203. TimeSpan ts = DateTime.Now - new DateTime(1999, 1, 1, 0, 0, 0, 0);
  204. int ss = Convert.ToInt32(ts.TotalSeconds);
  205. string key = DESEncrypt.Encrypt(ss.ToString(), "SSO" + LoginName);
  206. return new RedirectResult(string.Format("{2}/default/SSOShow?userid={0}&key={1}", LoginName, key, ConfigurationManager.AppSettings["domain"]));
  207. }
  208. }
  209. return View();
  210. }
  211. public ActionResult SSOShow()
  212. {
  213. ReturnData rd = new ReturnData { code = -1, msg = "默认错误",data= ConfigurationManager.AppSettings["sso"] };
  214. string userid = Request.QueryString["userid"].ToMyString();
  215. string key = Request.QueryString["key"].ToMyString();
  216. if (userid != "" && key != "")
  217. {
  218. TimeSpan ts = DateTime.Now - new DateTime(1999, 1, 1, 0, 0, 0, 0);
  219. int tsInt = Convert.ToInt32(ts.TotalSeconds);
  220. int tsKey = DESEncrypt.Decrypt(key, "SSO" + userid).ToInt32();
  221. //LogHelper.Default.WriteInfo("tsInt:" + tsInt.ToMyString());
  222. //LogHelper.Default.WriteInfo("tsKey:" + tsKey.ToMyString());
  223. if (tsInt - tsKey < 5)
  224. {
  225. DataTable dt = new DataTable();
  226. try
  227. {
  228. DataSet ds = busUserInfo.GetList(" F_UserCode=" + userid);
  229. if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
  230. {
  231. dt = ds.Tables[0];
  232. rd.code = 0;
  233. rd.msg = "成功";
  234. //记住用户名每3个月更换一次
  235. HttpCookie cookie = new HttpCookie("platform");
  236. cookie.Values.Add("Name", userid);
  237. cookie.Values.Add("islocal", "0");
  238. cookie.Expires = System.DateTime.Now.AddMonths(3);
  239. Response.Cookies.Add(cookie);
  240. string extensionphone = "";
  241. if (!string.IsNullOrEmpty(extensionphone))
  242. {
  243. }
  244. else if (string.IsNullOrEmpty(dt.Rows[0]["F_ExtensionNumber"].ToMyString()))
  245. {
  246. extensionphone = dt.Rows[0]["ExtensionCode"].ToMyString();
  247. }
  248. else
  249. {
  250. extensionphone = dt.Rows[0]["F_ExtensionNumber"].ToMyString();
  251. }
  252. int tempExtensionphone = GetNetworkAdpaterID();
  253. if (tempExtensionphone > 0)
  254. {
  255. extensionphone = tempExtensionphone.ToMyString();
  256. }
  257. Dictionary<string, string> Dic = new Dictionary<string, string>();
  258. Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToMyString());
  259. Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToMyString());
  260. Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToMyString());
  261. Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToMyString(), Encoding.UTF8));
  262. Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToMyString());
  263. Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToMyString());
  264. Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToMyString());
  265. Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToMyString());
  266. Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToMyString());
  267. Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToMyString());
  268. Dic.Add("F_ExtensionNumber", extensionphone);
  269. Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToMyString());
  270. CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
  271. //写入登录日志
  272. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  273. {
  274. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  275. F_LoginId = dt.Rows[0]["F_UserId"].ToInt32(),
  276. F_Result = "单点登录成功",
  277. F_LoginIP = Common.DTRequest.GetIP(),
  278. F_Hostname = Common.DTRequest.GetIP(),
  279. F_LoginDate = DateTime.Now,
  280. F_Remark = "",
  281. F_State = 0
  282. });
  283. Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  284. Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();
  285. //绑定登录用户分机号
  286. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  287. bll.UpdateWXId("ExtensionCode", extensionphone.ToInt32(), dt.Rows[0]["F_UserId"].ToInt32());
  288. }
  289. else
  290. {
  291. rd.msg = "没有权限";
  292. }
  293. }
  294. catch (Exception ex)
  295. {
  296. rd.msg = "error";
  297. LogHelper.Default.WriteError(ex.Message, ex);
  298. }
  299. finally
  300. {
  301. dt.Clear();
  302. dt.Dispose();
  303. }
  304. }
  305. else
  306. {
  307. rd.msg = "非法路径";
  308. }
  309. }
  310. else
  311. {
  312. rd.msg = "没有登录";
  313. }
  314. if (rd.code == 0)
  315. {
  316. return RedirectToAction("Index", "Main");
  317. }
  318. else
  319. return View(rd);
  320. }
  321. /// <summary>
  322. /// 获取网卡ID代码
  323. /// </summary>
  324. /// <returns></returns>
  325. public static int GetNetworkAdpaterID()
  326. {
  327. int ret = 0;
  328. //NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
  329. //if (nics != null && nics.Length > 0)
  330. //{
  331. // foreach (NetworkInterface nic in nics)
  332. // { string mac = nic.GetPhysicalAddress().ToString();
  333. // LogHelper.Default.WriteInfo("MAC:" + mac);
  334. // if (string.IsNullOrEmpty(mac))
  335. // continue;
  336. // ret = new BLL.T_Mac().GetNum(mac);
  337. // if (ret > 0)
  338. // {
  339. // LogHelper.Default.WriteInfo("MAC1:" + mac);
  340. // break;
  341. // }
  342. // }
  343. //}
  344. string mac = GetClientMAC();
  345. ret = new BLL.T_Mac().GetNum(mac);
  346. return ret;
  347. }
  348. [DllImport("Iphlpapi.dll")]
  349. private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
  350. [DllImport("Ws2_32.dll")]
  351. private static extern Int32 inet_addr(string ip);
  352. private static string GetClientMAC()
  353. {
  354. string mac_dest = string.Empty;
  355. // 在此处放置用户代码以初始化页面
  356. try
  357. {
  358. string userip = System.Web.HttpContext.Current.Request.UserHostAddress;
  359. string strClientIP = System.Web.HttpContext.Current.Request.UserHostAddress.ToString().Trim();
  360. Int32 ldest = inet_addr(strClientIP); //目的地的ip
  361. Int32 lhost = inet_addr(""); //本地服务器的ip
  362. Int64 macinfo = new Int64();
  363. Int32 len = 6;
  364. int res = SendARP(ldest, 0, ref macinfo, ref len);
  365. string mac_src = macinfo.ToString("X");
  366. while (mac_src.Length < 12)
  367. {
  368. mac_src = mac_src.Insert(0, "0");
  369. }
  370. for (int i = 0; i < 11; i++)
  371. {
  372. if (0 == (i % 2))
  373. {
  374. if (i == 10)
  375. {
  376. mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
  377. }
  378. else
  379. {
  380. mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
  381. }
  382. }
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. throw ex;
  388. }
  389. return mac_dest;
  390. }
  391. }
  392. }