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.
 
 
 
 
 
 

388 lines
14 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. private StuTransferInfoIBLL stuTransferInfoIBLL = new StuTransferInfoBLL();
  28. private StuInfoBasicTranIBLL stuInfoBasicTranIBLL = new StuInfoBasicTranBLL();
  29. #region 视图功能
  30. /// <summary>
  31. /// 个人中心
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. public ActionResult Index()
  36. {
  37. var baseUser = LoginUserInfo.Get();
  38. var userID = "";
  39. var checkMark = "";
  40. if (baseUser.Description == "教师")
  41. {
  42. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  43. if (teacher != null)
  44. {
  45. userID = teacher.EmpId;
  46. checkMark = teacher.CheckMark.ToString();
  47. }
  48. }
  49. else if (baseUser.Description == "学生")
  50. {
  51. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  52. if (student != null)
  53. {
  54. userID = student.StuId;
  55. checkMark = student.CheckMark?.ToString();
  56. }
  57. }
  58. ViewBag.UserType = baseUser.Description;
  59. ViewBag.UserID = userID;
  60. ViewBag.isCheck = checkMark;
  61. return View();
  62. }
  63. [HttpGet]
  64. public ActionResult IndexForDC()
  65. {
  66. var baseUser = LoginUserInfo.Get();
  67. var userID = "";
  68. var checkMark = "";
  69. if (baseUser.Description == "教师")
  70. {
  71. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  72. if (teacher != null)
  73. {
  74. userID = teacher.EmpId;
  75. checkMark = teacher.CheckMark.ToString();
  76. }
  77. }
  78. else if (baseUser.Description == "学生")
  79. {
  80. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  81. if (student != null)
  82. {
  83. userID = student.StuId;
  84. checkMark = student.CheckMark?.ToString();
  85. }
  86. }
  87. ViewBag.UserType = baseUser.Description;
  88. ViewBag.UserID = userID;
  89. ViewBag.isCheck = checkMark;
  90. return View();
  91. }
  92. /// <summary>
  93. /// 联系方式
  94. /// </summary>
  95. /// <returns></returns>
  96. [HttpGet]
  97. public ActionResult ContactForm()
  98. {
  99. return View();
  100. }
  101. /// <summary>
  102. /// 上传头像
  103. /// </summary>
  104. /// <returns></returns>
  105. [HttpGet]
  106. public ActionResult HeadForm()
  107. {
  108. return View();
  109. }
  110. /// <summary>
  111. /// 修改密码
  112. /// </summary>
  113. /// <returns></returns>
  114. [HttpGet]
  115. public ActionResult PassWordForm()
  116. {
  117. return View();
  118. }
  119. /// <summary>
  120. /// 个人中心-日志管理
  121. /// </summary>
  122. /// <returns></returns>
  123. [HttpGet]
  124. public ActionResult LogIndex()
  125. {
  126. return View();
  127. }
  128. /// <summary>
  129. /// 个人中心
  130. /// </summary>
  131. /// <returns></returns>
  132. [HttpGet]
  133. public ActionResult IndexInTeacher()
  134. {
  135. var baseUser = LoginUserInfo.Get();
  136. var userID = "";
  137. var checkMark = "";
  138. if (baseUser.Description == "教师")
  139. {
  140. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  141. if (teacher != null)
  142. {
  143. userID = teacher.EmpId;
  144. checkMark = teacher.CheckMark.ToString();
  145. }
  146. }
  147. else if (baseUser.Description == "学生")
  148. {
  149. var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode);
  150. if (student != null)
  151. {
  152. userID = student.StuId;
  153. checkMark = student.CheckMark?.ToString();
  154. }
  155. }
  156. ViewBag.UserType = baseUser.Description;
  157. ViewBag.UserID = userID;
  158. ViewBag.isCheck = checkMark;
  159. return View();
  160. }
  161. /// <summary>
  162. /// 个人中心-语言设置
  163. /// </summary>
  164. /// <returns></returns>
  165. [HttpGet]
  166. public ActionResult LanguageForm()
  167. {
  168. return View();
  169. }
  170. #endregion
  171. #region 获取数据
  172. /// <summary>
  173. /// 生成验证码
  174. /// </summary>
  175. /// <returns></returns>
  176. [HttpGet]
  177. public ActionResult VerifyCode()
  178. {
  179. return File(new VerifyCode().GetVerifyCode(), @"image/Gif");
  180. }
  181. [HttpGet]
  182. [AjaxOnly]
  183. public ActionResult GetUserInfo()
  184. {
  185. var data = LoginUserInfo.Get();
  186. data.password = null;
  187. data.secretkey = null;
  188. var jsonData = new
  189. {
  190. baseinfo = data,
  191. post = postIBLL.GetListByPostIds(data.postIds),
  192. role = roleIBLL.GetListByRoleIds(data.roleIds)
  193. };
  194. return JsonResult(jsonData);
  195. }
  196. public ActionResult GetStudentInfo(string stuId = null)
  197. {
  198. var data = LoginUserInfo.Get();
  199. var result = new StuInfoBasicEntity();
  200. if (stuId != null)
  201. {
  202. result = stuInfoBasicIBLL.GetStuInfoBasicEntity(stuId);
  203. }
  204. else
  205. {
  206. result = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(data.account);
  207. }
  208. if (result != null)
  209. {
  210. var photo = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  211. if (photo != null)
  212. {
  213. photo = "/" + photo.Substring(photo.IndexOf("Resource"));
  214. }
  215. else
  216. {
  217. photo = Config.GetValue("fileHeadImg") + "/" + (result.GenderNo == true ? "on-boy.jpg" : "on-girl.jpg");
  218. photo = "/" + photo.Substring(photo.IndexOf("Content"));
  219. }
  220. result.Photo = photo;
  221. }
  222. return Success(new { basicInfo = data, userInfo = result });
  223. }
  224. public ActionResult GetTeacherInfo()
  225. {
  226. var data = LoginUserInfo.Get();
  227. var result = empInfoIBLL.GetEmpInfoEntityByEmpNo(data.account);
  228. return Success(new { basecInfo = data, userInfo = result });
  229. }
  230. public ActionResult GetTeacherInfoById(string id)
  231. {
  232. var result = empInfoIBLL.GetEmpInfoEntityById(id);
  233. var baseInfo = userIBLL.GetEntityByAccount(result.EmpNo);
  234. var url = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  235. if (!string.IsNullOrEmpty(url))
  236. {
  237. url = "/" + url.Substring(url.IndexOf("Resource"));
  238. }
  239. return Success(new { basecInfo = baseInfo, userInfo = result, imgUrl = url });
  240. }
  241. /// <summary>
  242. /// 查看学生异动前的学生信息
  243. /// </summary>
  244. /// <param name="keyValue">StuTransferInfo 学籍异动表主键</param>
  245. /// <returns></returns>
  246. public ActionResult GetStudentInfoOfTran(string keyValue)
  247. {
  248. var result = new StuInfoBasicTranEntity();
  249. var StuTransferInfoEntity = stuTransferInfoIBLL.GetEntity(keyValue);
  250. var StuInfoBasicTranEntity = stuInfoBasicTranIBLL.GetEntity(StuTransferInfoEntity?.StuTranId);
  251. if (StuInfoBasicTranEntity != null)
  252. {
  253. var photo = annesexFileIBll.GetEntityByFolderId(StuInfoBasicTranEntity.Photo)?.F_FilePath;
  254. if (photo != null)
  255. {
  256. photo = "/" + photo.Substring(photo.IndexOf("Resource"));
  257. }
  258. else
  259. {
  260. photo = Config.GetValue("fileHeadImg") + "/" + (StuInfoBasicTranEntity.GenderNo == true ? "on-boy.jpg" : "on-girl.jpg");
  261. photo = "/" + photo.Substring(photo.IndexOf("Content"));
  262. }
  263. StuInfoBasicTranEntity.Photo = photo;
  264. result = StuInfoBasicTranEntity;
  265. }
  266. return Success(new { userInfo = result });
  267. }
  268. #endregion
  269. #region 提交数据
  270. /// <summary>
  271. /// 上传头像
  272. /// </summary>
  273. /// <returns></returns>
  274. [HttpPost]
  275. public ActionResult UploadFile()
  276. {
  277. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  278. //没有文件上传,直接返回
  279. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  280. {
  281. return HttpNotFound();
  282. }
  283. UserInfo userInfo = LoginUserInfo.Get();
  284. string FileEextension = Path.GetExtension(files[0].FileName);
  285. string filePath = Config.GetValue("AnnexesFile");
  286. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  287. string fileGuid = Guid.NewGuid().ToString();
  288. string fileHeadImg = Config.GetValue("AnnexesFile");
  289. //string fullFileName = string.Format("{0}/{1}{2}", fileHeadImg, userInfo.userId, FileEextension);
  290. string fullFileName = $"{fileHeadImg}/{userInfo.userId}/{uploadDate}/{fileGuid}{FileEextension}";
  291. var saveFileName = "/Resource/" + fullFileName.Substring(fullFileName.IndexOf(userInfo.userId), fullFileName.Length - fullFileName.IndexOf(userInfo.userId));
  292. //创建文件夹,保存文件
  293. string path = Path.GetDirectoryName(fullFileName);
  294. Directory.CreateDirectory(path);
  295. files[0].SaveAs(fullFileName);
  296. UserEntity userEntity = new UserEntity();
  297. userEntity.F_UserId = userInfo.userId;
  298. userEntity.F_Account = userInfo.account;
  299. userEntity.F_HeadIcon = saveFileName;
  300. userIBLL.SaveEntity(userEntity.F_UserId, userEntity);
  301. return Success("上传成功。");
  302. }
  303. /// <summary>
  304. /// 验证旧密码
  305. /// </summary>
  306. /// <param name="OldPassword"></param>
  307. /// <returns></returns>
  308. [HttpPost]
  309. [AjaxOnly]
  310. public ActionResult ValidationOldPassword(string OldPassword)
  311. {
  312. UserInfo userInfo = LoginUserInfo.Get();
  313. var entity = userIBLL.GetEntityByUserId(userInfo.userId);
  314. OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  315. if (OldPassword != entity.F_Password)
  316. {
  317. return Fail("原密码错误,请重新输入");
  318. }
  319. else
  320. {
  321. return Success("通过信息验证");
  322. }
  323. }
  324. /// <summary>
  325. /// 提交修改密码
  326. /// </summary>
  327. /// <param name="password">新密码</param>
  328. /// <param name="oldPassword">旧密码</param>
  329. /// <param name="verifyCode">验证码</param>
  330. /// <returns></returns>
  331. [HttpPost]
  332. [AjaxOnly]
  333. public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode)
  334. {
  335. verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16);
  336. if (Session["session_verifycode"].IsEmpty() || verifyCode != Session["session_verifycode"].ToString())
  337. {
  338. return Fail("验证码错误,请重新输入");
  339. }
  340. bool res = userIBLL.RevisePassword(password, oldPassword);
  341. if (!res)
  342. {
  343. return Fail("原密码错误,请重新输入");
  344. }
  345. Session.Abandon();
  346. Session.Clear();
  347. OperatorHelper.Instance.EmptyCurrent();
  348. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  349. }
  350. [HttpPost]
  351. [AjaxOnly]
  352. public ActionResult SubmitResetPasswordNoCode(string password, string oldPassword)
  353. {
  354. bool res = userIBLL.RevisePassword(password, oldPassword);
  355. if (!res)
  356. {
  357. return Fail("原密码错误,请重新输入");
  358. }
  359. Session.Abandon();
  360. Session.Clear();
  361. OperatorHelper.Instance.EmptyCurrent();
  362. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  363. }
  364. #endregion
  365. }
  366. }