地铁二期项目正式开始

DefaultController.cs 16KB

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