You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

345 lines
12 KiB

  1. using Learun.Application.Base.SystemModule;
  2. using Learun.Application.Organization;
  3. using Learun.Application.TwoDevelopment.EducationalAdministration;
  4. using Learun.Util;
  5. using Learun.Util.Operat;
  6. using System;
  7. using System.IO;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace Learun.Application.Web.Controllers
  11. {
  12. /// <summary>
  13. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  14. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  15. /// 创建人:陈彬彬
  16. /// 日 期:2017.03.07
  17. /// 描 述:个人中心
  18. /// </summary>
  19. public class UserCenterController : MvcControllerBase
  20. {
  21. private UserIBLL userIBLL = new UserBLL();
  22. private PostIBLL postIBLL = new PostBLL();
  23. private RoleIBLL roleIBLL = new RoleBLL();
  24. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  25. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  26. private AnnexesFileIBLL annesexFileIBll = new AnnexesFileBLL();
  27. #region 视图功能
  28. /// <summary>
  29. /// 个人中心
  30. /// </summary>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public ActionResult Index()
  34. {
  35. var baseUser = LoginUserInfo.Get();
  36. var userID = "";
  37. var checkMark = "";
  38. if (baseUser.Description == "教师")
  39. {
  40. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  41. if (teacher != null)
  42. {
  43. userID = teacher.EmpId;
  44. checkMark = teacher.CheckMark.ToString();
  45. }
  46. }
  47. else if (baseUser.Description == "学生")
  48. {
  49. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  50. if (student != null)
  51. {
  52. userID = student.StuId;
  53. checkMark = student.CheckMark?.ToString();
  54. }
  55. }
  56. ViewBag.UserType = baseUser.Description;
  57. ViewBag.UserID = userID;
  58. ViewBag.isCheck = checkMark;
  59. return View();
  60. }
  61. [HttpGet]
  62. public ActionResult IndexForDC()
  63. {
  64. var baseUser = LoginUserInfo.Get();
  65. var userID = "";
  66. var checkMark = "";
  67. if (baseUser.Description == "教师")
  68. {
  69. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  70. if (teacher != null)
  71. {
  72. userID = teacher.EmpId;
  73. checkMark = teacher.CheckMark.ToString();
  74. }
  75. }
  76. else if (baseUser.Description == "学生")
  77. {
  78. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  79. if (student != null)
  80. {
  81. userID = student.StuId;
  82. checkMark = student.CheckMark?.ToString();
  83. }
  84. }
  85. ViewBag.UserType = baseUser.Description;
  86. ViewBag.UserID = userID;
  87. ViewBag.isCheck = checkMark;
  88. return View();
  89. }
  90. /// <summary>
  91. /// 联系方式
  92. /// </summary>
  93. /// <returns></returns>
  94. [HttpGet]
  95. public ActionResult ContactForm()
  96. {
  97. return View();
  98. }
  99. /// <summary>
  100. /// 上传头像
  101. /// </summary>
  102. /// <returns></returns>
  103. [HttpGet]
  104. public ActionResult HeadForm()
  105. {
  106. return View();
  107. }
  108. /// <summary>
  109. /// 修改密码
  110. /// </summary>
  111. /// <returns></returns>
  112. [HttpGet]
  113. public ActionResult PassWordForm()
  114. {
  115. return View();
  116. }
  117. /// <summary>
  118. /// 个人中心-日志管理
  119. /// </summary>
  120. /// <returns></returns>
  121. [HttpGet]
  122. public ActionResult LogIndex()
  123. {
  124. return View();
  125. }
  126. /// <summary>
  127. /// 个人中心
  128. /// </summary>
  129. /// <returns></returns>
  130. [HttpGet]
  131. public ActionResult IndexInTeacher()
  132. {
  133. var baseUser = LoginUserInfo.Get();
  134. var userID = "";
  135. var checkMark = "";
  136. if (baseUser.Description == "教师")
  137. {
  138. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  139. if (teacher != null)
  140. {
  141. userID = teacher.EmpId;
  142. checkMark = teacher.CheckMark.ToString();
  143. }
  144. }
  145. else if (baseUser.Description == "学生")
  146. {
  147. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  148. if (student != null)
  149. {
  150. userID = student.StuId;
  151. checkMark = student.CheckMark?.ToString();
  152. }
  153. }
  154. ViewBag.UserType = baseUser.Description;
  155. ViewBag.UserID = userID;
  156. ViewBag.isCheck = checkMark;
  157. return View();
  158. }
  159. #endregion
  160. #region 获取数据
  161. /// <summary>
  162. /// 生成验证码
  163. /// </summary>
  164. /// <returns></returns>
  165. [HttpGet]
  166. public ActionResult VerifyCode()
  167. {
  168. return File(new VerifyCode().GetVerifyCode(), @"image/Gif");
  169. }
  170. [HttpGet]
  171. [AjaxOnly]
  172. public ActionResult GetUserInfo()
  173. {
  174. var data = LoginUserInfo.Get();
  175. data.password = null;
  176. data.secretkey = null;
  177. var jsonData = new
  178. {
  179. baseinfo = data,
  180. post = postIBLL.GetListByPostIds(data.postIds),
  181. role = roleIBLL.GetListByRoleIds(data.roleIds)
  182. };
  183. return JsonResult(jsonData);
  184. }
  185. public ActionResult GetStudentInfo(string stuNo = null)
  186. {
  187. var data = LoginUserInfo.Get();
  188. var result = new StuInfoBasicEntity();
  189. if (stuNo != null)
  190. {
  191. result = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(stuNo);
  192. }
  193. else
  194. {
  195. result = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(data.account);
  196. }
  197. if (result != null)
  198. {
  199. var photo = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  200. if (photo != null)
  201. {
  202. photo = "/" + photo.Substring(photo.IndexOf("Resource"));
  203. }
  204. result.Photo = photo;
  205. }
  206. return Success(new { basicInfo = data, userInfo = result });
  207. }
  208. public ActionResult GetTeacherInfo()
  209. {
  210. var data = LoginUserInfo.Get();
  211. var result = empInfoIBLL.GetEmpInfoEntityByEmpNo(data.account);
  212. return Success(new { basecInfo = data, userInfo = result });
  213. }
  214. public ActionResult GetTeacherInfoById(string id)
  215. {
  216. var result = empInfoIBLL.GetEmpInfoEntityById(id);
  217. var baseInfo = userIBLL.GetEntityByAccount(result.EmpNo);
  218. var url = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  219. if (!string.IsNullOrEmpty(url))
  220. {
  221. url = "/" + url.Substring(url.IndexOf("Resource"));
  222. }
  223. return Success(new { basecInfo = baseInfo, userInfo = result, imgUrl = url });
  224. }
  225. #endregion
  226. #region 提交数据
  227. /// <summary>
  228. /// 上传头像
  229. /// </summary>
  230. /// <returns></returns>
  231. [HttpPost]
  232. public ActionResult UploadFile()
  233. {
  234. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  235. //没有文件上传,直接返回
  236. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  237. {
  238. return HttpNotFound();
  239. }
  240. UserInfo userInfo = LoginUserInfo.Get();
  241. string FileEextension = Path.GetExtension(files[0].FileName);
  242. string filePath = Config.GetValue("AnnexesFile");
  243. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  244. string fileGuid = Guid.NewGuid().ToString();
  245. string fileHeadImg = Config.GetValue("AnnexesFile");
  246. //string fullFileName = string.Format("{0}/{1}{2}", fileHeadImg, userInfo.userId, FileEextension);
  247. string fullFileName = $"{fileHeadImg}/{userInfo.userId}/{uploadDate}/{fileGuid}{FileEextension}";
  248. var saveFileName = "/Resource/" + fullFileName.Substring(fullFileName.IndexOf(userInfo.userId), fullFileName.Length - fullFileName.IndexOf(userInfo.userId));
  249. //创建文件夹,保存文件
  250. string path = Path.GetDirectoryName(fullFileName);
  251. Directory.CreateDirectory(path);
  252. files[0].SaveAs(fullFileName);
  253. UserEntity userEntity = new UserEntity();
  254. userEntity.F_UserId = userInfo.userId;
  255. userEntity.F_Account = userInfo.account;
  256. userEntity.F_HeadIcon = saveFileName;
  257. userIBLL.SaveEntity(userEntity.F_UserId, userEntity);
  258. return Success("上传成功。");
  259. }
  260. /// <summary>
  261. /// 验证旧密码
  262. /// </summary>
  263. /// <param name="OldPassword"></param>
  264. /// <returns></returns>
  265. [HttpPost]
  266. [AjaxOnly]
  267. public ActionResult ValidationOldPassword(string OldPassword)
  268. {
  269. UserInfo userInfo = LoginUserInfo.Get();
  270. var entity = userIBLL.GetEntityByUserId(userInfo.userId);
  271. OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  272. if (OldPassword != entity.F_Password)
  273. {
  274. return Fail("原密码错误,请重新输入");
  275. }
  276. else
  277. {
  278. return Success("通过信息验证");
  279. }
  280. }
  281. /// <summary>
  282. /// 提交修改密码
  283. /// </summary>
  284. /// <param name="password">新密码</param>
  285. /// <param name="oldPassword">旧密码</param>
  286. /// <param name="verifyCode">验证码</param>
  287. /// <returns></returns>
  288. [HttpPost]
  289. [AjaxOnly]
  290. public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode)
  291. {
  292. verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16);
  293. if (Session["session_verifycode"].IsEmpty() || verifyCode != Session["session_verifycode"].ToString())
  294. {
  295. return Fail("验证码错误,请重新输入");
  296. }
  297. bool res = userIBLL.RevisePassword(password, oldPassword);
  298. if (!res)
  299. {
  300. return Fail("原密码错误,请重新输入");
  301. }
  302. Session.Abandon();
  303. Session.Clear();
  304. OperatorHelper.Instance.EmptyCurrent();
  305. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  306. }
  307. [HttpPost]
  308. [AjaxOnly]
  309. public ActionResult SubmitResetPasswordNoCode(string password, string oldPassword)
  310. {
  311. bool res = userIBLL.RevisePassword(password, oldPassword);
  312. if (!res)
  313. {
  314. return Fail("原密码错误,请重新输入");
  315. }
  316. Session.Abandon();
  317. Session.Clear();
  318. OperatorHelper.Instance.EmptyCurrent();
  319. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  320. }
  321. #endregion
  322. }
  323. }