地铁二期项目正式开始

DefaultController.cs 16KB

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