UserServicesController.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using EMIS.CommonLogic.SystemServices;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Web.Mvc;
  8. using EMIS.Web.Controls;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.SystemView;
  11. using Bowin.Web.Controls.Mvc;
  12. using EMIS.Utility;
  13. using Bowin.Common.Utility;
  14. using System.Web.Http;
  15. using System.Configuration;
  16. namespace EMIS.Web.ServiceControllers.SystemManage
  17. {
  18. public class UserServicesController : Controller
  19. {
  20. //
  21. // GET: /UserServices/
  22. public IUserServices UserServices { get; set; }
  23. public IWechatMPServices WechatMPServices { get; set; }
  24. public IMailVerifyServices MailVerifyServices { get; set; }
  25. [System.Web.Http.HttpPost]
  26. public ActionResult Login(string loginID, string password, string openID)
  27. {
  28. if (loginID == null)
  29. {
  30. return Json(new ReturnMessage { IsSuccess = false, Message = "没有接收loginid" });
  31. }
  32. password = Bowin.Common.Utility.StringEx.MD5(password);
  33. var isLogined = UserServices.Login(loginID, password);
  34. bool isCanLogin = UserServices.LoginHistory(loginID, isLogined);
  35. if (ConfigurationManager.AppSettings["WeixinOnDebug"] != "1")
  36. {
  37. try
  38. {
  39. if (!isCanLogin)
  40. {
  41. throw new Exception("当天登陆失败次数超过5次,请明天再试或联系管理员。");
  42. }
  43. if (openID != null && openID != "null")
  44. {
  45. WechatMPServices.BindOpenID(loginID, openID);
  46. }
  47. else if (openID == "null")
  48. {
  49. throw new Exception("微信openid获取失败,请关注公众号之后,刷新页面重试!如果已经关注公众号,请联系老师或管理员。");
  50. }
  51. }
  52. catch (Exception ex)
  53. {
  54. return Json(new ReturnMessage { IsSuccess = false, Message = ex.Message });
  55. }
  56. }
  57. return Json(new ReturnMessage { IsSuccess = isLogined, Message = "密码错误或不存在该账户!(注意:如密码连续输入错误5次以上账号将被锁定)" });
  58. }
  59. public ActionResult LoginP(string loginID, string password)
  60. {
  61. password = Bowin.Common.Utility.StringEx.MD5(password);
  62. return new JSONPResult { Data = UserServices.Login(loginID, password) };
  63. }
  64. public ActionResult Regist(RegistView model, string openID)
  65. {
  66. try
  67. {
  68. UserServices.StudentRegist(model);
  69. try
  70. {
  71. if (openID != null)
  72. {
  73. WechatMPServices.BindOpenID(model.LoginID, openID);
  74. }
  75. }
  76. catch
  77. {
  78. }
  79. return Json(new ReturnMessage<Guid?> { IsSuccess = true, Message = "注册成功", Data = model.UserID });
  80. }
  81. catch (Exception ex)
  82. {
  83. return Json(new ReturnMessage { IsSuccess = false, Message = "注册失败,原因:" + ex.Message });
  84. }
  85. }
  86. public ActionResult UnBind(string openID)
  87. {
  88. if (openID != null)
  89. {
  90. try
  91. {
  92. WechatMPServices.UnBindOpenID(openID);
  93. return Json(new ReturnMessage { IsSuccess = true, Message = "解除绑定成功" });
  94. }
  95. catch (Exception ex)
  96. {
  97. return Json(new ReturnMessage { IsSuccess = false, Message = "解除绑定失败,原因:" + ex.Message });
  98. }
  99. }
  100. else
  101. {
  102. return Json(new ReturnMessage { IsSuccess = true, Message = "解除绑定成功" });
  103. }
  104. }
  105. public ActionResult GetSchoolAreaWithoutSocial(DropdownListBindType? bindType)
  106. {
  107. List<DropdownListItem> list = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_SchoolArea)
  108. .Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.Value < 3)
  109. .Select(x => new DropdownListItem { Text = x.Name, Value = x.Value.ToString() }).ToList();
  110. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  111. DropdownList.FormatDropdownItemList(dbt, list);
  112. return base.Json(list);
  113. }
  114. [System.Web.Http.HttpPost]
  115. public ActionResult ChangePassword(ChangePasswordView changePasswordView, Guid userID)
  116. {
  117. try
  118. {
  119. var user = UserServices.GetUserByID(userID);
  120. if (user.Password.ToLower() != changePasswordView.OldPassword.MD5().ToLower())
  121. {
  122. return Json(new ReturnMessage()
  123. {
  124. IsSuccess = false,
  125. Message = "保存失败:原密码验证失败"
  126. });
  127. }
  128. UserServices.ChangePassword(changePasswordView, user.UserID);
  129. return Json(new ReturnMessage()
  130. {
  131. IsSuccess = true,
  132. Message = "密码已经成功修改!"
  133. });
  134. }
  135. catch (Exception ex)
  136. {
  137. return Json(new ReturnMessage()
  138. {
  139. IsSuccess = false,
  140. Message = "保存失败:" + ex.Message
  141. });
  142. }
  143. }
  144. //[HttpPost]
  145. //public ActionResult ForgotPassword(string LoginID)
  146. //{
  147. // var result = new ReturnMessage { IsSuccess = true, Message = "邮件发送成功,请查收。" };
  148. // //string loginID = Request.Form["LoginID"];
  149. // string failUrl = Url.Content("~/Account/ForgotPassword?LoginID=" + LoginID);
  150. // string successUrl = Url.Content("~/Account/Login");
  151. // var user = UserServices.GetUserByLoginID(LoginID);
  152. // if (user == null)
  153. // {
  154. // result.IsSuccess = false;
  155. // result.Message = "用户名输入错误。";
  156. // return Json(result);
  157. // }
  158. // var url = HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port + Url.Content("~/").TrimEnd('/');
  159. // try
  160. // {
  161. // var email = UserServices.GetUserEmail(user.UserID);
  162. // if (email == null)
  163. // {
  164. // result.IsSuccess = false;
  165. // result.Message = "用户并没有注册电子邮箱信息。";
  166. // return Json(result);
  167. // }
  168. // MailVerifyServices.SendVerifyMail(url, user.UserID, email);
  169. // return Json(result);
  170. // }
  171. // catch (Exception ex)
  172. // {
  173. // result.IsSuccess = false;
  174. // result.Message = ex.Message;
  175. // return Json(result);
  176. // }
  177. //}
  178. }
  179. }