地铁二期项目正式开始

DefaultController.cs 17KB

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