UserServicesController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. namespace EMIS.Web.ServiceControllers.SystemManage
  12. {
  13. public class UserServicesController : Controller
  14. {
  15. //
  16. // GET: /UserServices/
  17. public IUserServices UserServices { get; set; }
  18. public IWechatMPServices WechatMPServices { get; set; }
  19. public IMailVerifyServices MailVerifyServices { get; set; }
  20. public ActionResult Login(string loginID, string password, string openID)
  21. {
  22. password = Bowin.Common.Utility.StringEx.MD5(password);
  23. var isLogined = UserServices.Login(loginID, password);
  24. bool isCanLogin = UserServices.LoginHistory(loginID, isLogined);
  25. try
  26. {
  27. if (!isCanLogin)
  28. {
  29. throw new Exception("当天登陆失败次数超过5次,请明天再试或联系管理员。");
  30. }
  31. if (openID != null && openID != "null")
  32. {
  33. WechatMPServices.BindOpenID(loginID, openID);
  34. }
  35. else if (openID == "null")
  36. {
  37. throw new Exception("微信openid获取失败,请关注公众号之后,刷新页面重试!如果已经关注公众号,请联系老师或管理员。");
  38. }
  39. }
  40. catch(Exception ex)
  41. {
  42. return Json(new ReturnMessage { IsSuccess = false, Message = ex.Message });
  43. }
  44. return Json(new ReturnMessage { IsSuccess = isLogined, Message = "密码错误或不存在该账户!(注意:如密码连续输入错误5次以上账号将被锁定)" });
  45. }
  46. public ActionResult LoginP(string loginID, string password)
  47. {
  48. password = Bowin.Common.Utility.StringEx.MD5(password);
  49. return new JSONPResult { Data = UserServices.Login(loginID, password) };
  50. }
  51. public ActionResult Regist(RegistView model, string openID)
  52. {
  53. try
  54. {
  55. UserServices.StudentRegist(model);
  56. try
  57. {
  58. if (openID != null)
  59. {
  60. WechatMPServices.BindOpenID(model.LoginID, openID);
  61. }
  62. }
  63. catch
  64. {
  65. }
  66. return Json(new ReturnMessage<Guid?> { IsSuccess = true, Message = "注册成功", Data = model.UserID });
  67. }
  68. catch (Exception ex)
  69. {
  70. return Json(new ReturnMessage { IsSuccess = false, Message = "注册失败,原因:" + ex.Message });
  71. }
  72. }
  73. public ActionResult UnBind(string openID)
  74. {
  75. if (openID != null)
  76. {
  77. try
  78. {
  79. WechatMPServices.UnBindOpenID(openID);
  80. return Json(new ReturnMessage { IsSuccess = true, Message = "解除绑定成功" });
  81. }
  82. catch (Exception ex)
  83. {
  84. return Json(new ReturnMessage { IsSuccess = false, Message = "解除绑定失败,原因:" + ex.Message });
  85. }
  86. }
  87. else
  88. {
  89. return Json(new ReturnMessage { IsSuccess = true, Message = "解除绑定成功" });
  90. }
  91. }
  92. //[HttpPost]
  93. //public ActionResult ForgotPassword(string LoginID)
  94. //{
  95. // var result = new ReturnMessage { IsSuccess = true, Message = "邮件发送成功,请查收。" };
  96. // //string loginID = Request.Form["LoginID"];
  97. // string failUrl = Url.Content("~/Account/ForgotPassword?LoginID=" + LoginID);
  98. // string successUrl = Url.Content("~/Account/Login");
  99. // var user = UserServices.GetUserByLoginID(LoginID);
  100. // if (user == null)
  101. // {
  102. // result.IsSuccess = false;
  103. // result.Message = "用户名输入错误。";
  104. // return Json(result);
  105. // }
  106. // var url = HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port + Url.Content("~/").TrimEnd('/');
  107. // try
  108. // {
  109. // var email = UserServices.GetUserEmail(user.UserID);
  110. // if (email == null)
  111. // {
  112. // result.IsSuccess = false;
  113. // result.Message = "用户并没有注册电子邮箱信息。";
  114. // return Json(result);
  115. // }
  116. // MailVerifyServices.SendVerifyMail(url, user.UserID, email);
  117. // return Json(result);
  118. // }
  119. // catch (Exception ex)
  120. // {
  121. // result.IsSuccess = false;
  122. // result.Message = ex.Message;
  123. // return Json(result);
  124. // }
  125. //}
  126. }
  127. }