地铁二期项目正式开始

DefaultController.cs 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using YTSoft.BaseCallCenter.Model;
  10. using YTSoft.BaseCallCenter.MVCWeb.Models;
  11. using YTSoft.Common;
  12. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  13. {
  14. public class DefaultController : Controller
  15. {
  16. BLL.T_Sys_UserAccount busUserInfo = new BLL.T_Sys_UserAccount();
  17. public ActionResult Login()
  18. {
  19. T_Sys_UserAccount userInfo = new T_Sys_UserAccount();
  20. HttpCookie cookies = Request.Cookies["platform"];
  21. //判断是否有cookie值,有的话就读取出来
  22. if (cookies != null && cookies.HasKeys)
  23. {
  24. userInfo.F_UserName = cookies["Name"];
  25. }
  26. userInfo.ExtensionCode = ConfigurationManager.AppSettings["sso"].ToMyString();
  27. // userInfo.F_UserName = SystemInfo.GetCpuPerformancevalue();
  28. return View(userInfo);
  29. }
  30. [AcceptVerbs(HttpVerbs.Post)]
  31. public string LoginIn(string username, string extensionphone, string password)
  32. {
  33. string res = "未知错误,请重新登录";
  34. DataTable dt = new DataTable();
  35. try
  36. {
  37. dt = busUserInfo.GetList(username, password).Tables[0];
  38. if (dt != null)
  39. {
  40. if (dt.Rows.Count > 0)
  41. {
  42. if (dt.Rows[0]["F_UserCode"].ToString() == dt.Rows[0]["F_PassWord"].ToString())
  43. {
  44. res = "firstlogin" + dt.Rows[0]["F_UserId"].ToString();
  45. }
  46. else
  47. {
  48. //记住用户名每3个月更换一次
  49. HttpCookie cookie = new HttpCookie("platform");
  50. cookie.Values.Add("Name", username);
  51. cookie.Values.Add("islocal", "1");
  52. cookie.Expires = System.DateTime.Now.AddMonths(3);
  53. Response.Cookies.Add(cookie);
  54. if (!string.IsNullOrEmpty(extensionphone))
  55. {
  56. }
  57. else if (string.IsNullOrEmpty(dt.Rows[0]["F_ExtensionNumber"].ToMyString()))
  58. {
  59. extensionphone = dt.Rows[0]["ExtensionCode"].ToMyString();
  60. }
  61. else
  62. {
  63. extensionphone = dt.Rows[0]["F_ExtensionNumber"].ToMyString();
  64. }
  65. Dictionary<string, string> Dic = new Dictionary<string, string>();
  66. Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString());
  67. Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString());
  68. Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
  69. Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToString(), Encoding.UTF8));
  70. Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
  71. Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
  72. Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
  73. Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToString());
  74. if (dt.Rows[0]["F_GroupId"].ToString() != null)
  75. {
  76. Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
  77. }
  78. if (dt.Rows[0]["F_SeatRight"].ToString() != null)
  79. {
  80. Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
  81. }
  82. Dic.Add("F_ExtensionNumber", extensionphone);
  83. Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
  84. CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
  85. //写入登录日志
  86. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  87. {
  88. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  89. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  90. F_Result = "登录成功",
  91. F_LoginIP = Common.DTRequest.GetIP(),
  92. F_Hostname = Common.DTRequest.GetIP(),
  93. F_LoginDate = DateTime.Now,
  94. F_Remark = "",
  95. F_State = 0
  96. });
  97. Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  98. Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();//Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  99. res = "success";
  100. //绑定登录用户分机号
  101. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  102. bll.UpdateWXId("ExtensionCode",extensionphone.ToInt32(), Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); }
  103. }
  104. else
  105. {
  106. //写入登录日志
  107. DataTable dt1 = busUserInfo.GetList("F_UserCode='" + username + "'").Tables[0];
  108. if (dt1.Rows.Count > 0)
  109. {
  110. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  111. {
  112. F_LoginName = dt1.Rows[0]["F_UserName"].ToString(),
  113. F_LoginId = Convert.ToInt32(dt1.Rows[0]["F_UserId"].ToString()),
  114. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  115. F_LoginIP = Common.DTRequest.GetIP(),
  116. F_Hostname = Common.DTRequest.GetIP(),
  117. F_LoginDate = DateTime.Now,
  118. F_Remark = "",
  119. F_State = 0
  120. });
  121. }
  122. else
  123. {
  124. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  125. {
  126. F_LoginName = username,
  127. F_LoginId = -1,
  128. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  129. F_LoginIP = Common.DTRequest.GetIP(),
  130. F_Hostname = Common.DTRequest.GetIP(),
  131. F_LoginDate = DateTime.Now,
  132. F_Remark = "",
  133. F_State = 0
  134. });
  135. }
  136. res = "账号或密码错误,请重新登录";
  137. }
  138. }
  139. else
  140. {
  141. res = "账号或密码错误,请重新登录";
  142. }
  143. }
  144. catch (Exception ex)
  145. {
  146. res = "错误:" + ex.ToString();
  147. SysLog.WriteLog(ex);
  148. }
  149. finally
  150. {
  151. dt.Clear();
  152. dt.Dispose();
  153. }
  154. return res;
  155. }
  156. //退出系统
  157. [AcceptVerbs(HttpVerbs.Post)]
  158. public string LoginOut(string username)
  159. {
  160. string res = "未知错误,请重新登录";
  161. DataTable dt = new DataTable();
  162. try {
  163. string userid = Request.Cookies["BaseCallCenter_T_User"]["F_UserId"];
  164. dt = busUserInfo.GetList("F_UserId='" + userid + "'").Tables[0];
  165. //写入登录日志
  166. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  167. {
  168. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  169. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  170. F_Result = "退出系统成功",
  171. F_LoginIP = Common.DTRequest.GetIP(),
  172. F_Hostname = Common.DTRequest.GetIP(),
  173. F_LoginDate = DateTime.Now,
  174. F_Remark = "",
  175. F_State = 0
  176. });
  177. res = "success";
  178. //绑定登录用户分机号
  179. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  180. bll.UpdateWXId("ExtensionCode", 0, Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()));
  181. }
  182. catch(Exception){ }
  183. return res;
  184. }
  185. public ActionResult SSO()
  186. {
  187. bool res = false; //标记是否登录
  188. string LoginName=Request.Headers.Get("OAM_REMOTE_USER");
  189. LogHelper.Default.WriteInfo("LoginName:" + LoginName.ToMyString());
  190. if (!string.IsNullOrEmpty(LoginName))
  191. {
  192. if (!"Anonymous".Equals(LoginName))
  193. {
  194. res = true;
  195. TimeSpan ts = DateTime.Now - new DateTime(1999, 1, 1, 0, 0, 0, 0);
  196. int ss = Convert.ToInt32(ts.TotalSeconds);
  197. string key = DESEncrypt.Encrypt(ss.ToString(), "SSO" + LoginName);
  198. return new RedirectResult(string.Format("{2}/default/SSOShow?userid={0}&key={1}", LoginName, key, ConfigurationManager.AppSettings["domain"]));
  199. }
  200. }
  201. return View();
  202. }
  203. public ActionResult SSOShow()
  204. {
  205. ReturnData rd = new ReturnData { code = -1, msg = "默认错误",data= ConfigurationManager.AppSettings["sso"] };
  206. string userid = Request.QueryString["userid"].ToMyString();
  207. string key = Request.QueryString["key"].ToMyString();
  208. if (userid != "" && key != "")
  209. {
  210. TimeSpan ts = DateTime.Now - new DateTime(1999, 1, 1, 0, 0, 0, 0);
  211. int tsInt = Convert.ToInt32(ts.TotalSeconds);
  212. int tsKey = DESEncrypt.Decrypt(key, "SSO" + userid).ToInt32();
  213. LogHelper.Default.WriteInfo("tsInt:" + tsInt.ToMyString());
  214. LogHelper.Default.WriteInfo("tsKey:" + tsKey.ToMyString());
  215. if (tsInt - tsKey < 5)
  216. {
  217. DataTable dt = new DataTable();
  218. try
  219. {
  220. DataSet ds = busUserInfo.GetList(" F_UserCode=" + userid);
  221. if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
  222. {
  223. dt = ds.Tables[0];
  224. rd.code = 0;
  225. rd.msg = "成功";
  226. //记住用户名每3个月更换一次
  227. HttpCookie cookie = new HttpCookie("platform");
  228. cookie.Values.Add("Name", userid);
  229. cookie.Values.Add("islocal", "0");
  230. cookie.Expires = System.DateTime.Now.AddMonths(3);
  231. Response.Cookies.Add(cookie);
  232. string extensionphone = "";
  233. if (!string.IsNullOrEmpty(extensionphone))
  234. {
  235. }
  236. else if (string.IsNullOrEmpty(dt.Rows[0]["F_ExtensionNumber"].ToMyString()))
  237. {
  238. extensionphone = dt.Rows[0]["ExtensionCode"].ToMyString();
  239. }
  240. else
  241. {
  242. extensionphone = dt.Rows[0]["F_ExtensionNumber"].ToMyString();
  243. }
  244. Dictionary<string, string> Dic = new Dictionary<string, string>();
  245. Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToMyString());
  246. Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToMyString());
  247. Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToMyString());
  248. Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToMyString(), Encoding.UTF8));
  249. Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToMyString());
  250. Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToMyString());
  251. Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToMyString());
  252. Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToMyString());
  253. Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToMyString());
  254. Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToMyString());
  255. Dic.Add("F_ExtensionNumber", extensionphone);
  256. Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToMyString());
  257. CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
  258. //写入登录日志
  259. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  260. {
  261. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  262. F_LoginId = dt.Rows[0]["F_UserId"].ToInt32(),
  263. F_Result = "单点登录成功",
  264. F_LoginIP = Common.DTRequest.GetIP(),
  265. F_Hostname = Common.DTRequest.GetIP(),
  266. F_LoginDate = DateTime.Now,
  267. F_Remark = "",
  268. F_State = 0
  269. });
  270. Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  271. Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();
  272. //绑定登录用户分机号
  273. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  274. bll.UpdateWXId("ExtensionCode", extensionphone.ToInt32(), dt.Rows[0]["F_UserId"].ToInt32());
  275. }
  276. else
  277. {
  278. rd.msg = "没有权限";
  279. }
  280. }
  281. catch (Exception ex)
  282. {
  283. rd.msg = "error";
  284. LogHelper.Default.WriteError(ex.Message, ex);
  285. }
  286. finally
  287. {
  288. dt.Clear();
  289. dt.Dispose();
  290. }
  291. }
  292. else
  293. {
  294. rd.msg = "非法路径";
  295. }
  296. }
  297. else
  298. {
  299. rd.msg = "没有登录";
  300. }
  301. if (rd.code == 0)
  302. {
  303. return RedirectToAction("Index", "Main");
  304. }
  305. else
  306. return View(rd);
  307. }
  308. }
  309. }