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.
 
 
 
 
 
 

358 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. /// <summary>
  160. /// 个人中心-语言设置
  161. /// </summary>
  162. /// <returns></returns>
  163. [HttpGet]
  164. public ActionResult LanguageForm()
  165. {
  166. return View();
  167. }
  168. #endregion
  169. #region 获取数据
  170. /// <summary>
  171. /// 生成验证码
  172. /// </summary>
  173. /// <returns></returns>
  174. [HttpGet]
  175. public ActionResult VerifyCode()
  176. {
  177. return File(new VerifyCode().GetVerifyCode(), @"image/Gif");
  178. }
  179. [HttpGet]
  180. [AjaxOnly]
  181. public ActionResult GetUserInfo()
  182. {
  183. var data = LoginUserInfo.Get();
  184. data.password = null;
  185. data.secretkey = null;
  186. var jsonData = new
  187. {
  188. baseinfo = data,
  189. post = postIBLL.GetListByPostIds(data.postIds),
  190. role = roleIBLL.GetListByRoleIds(data.roleIds)
  191. };
  192. return JsonResult(jsonData);
  193. }
  194. public ActionResult GetStudentInfo(string stuId = null)
  195. {
  196. var data = LoginUserInfo.Get();
  197. var result = new StuInfoBasicEntity();
  198. if (stuId != null)
  199. {
  200. result = stuInfoBasicIBLL.GetStuInfoBasicEntity(stuId);
  201. }
  202. else
  203. {
  204. result = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(data.account);
  205. }
  206. if (result != null)
  207. {
  208. var photo = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  209. if (photo != null)
  210. {
  211. photo = "/" + photo.Substring(photo.IndexOf("Resource"));
  212. }
  213. else
  214. {
  215. photo = Config.GetValue("fileHeadImg") +"/"+ (result.GenderNo==true? "on-boy.jpg" : "on-girl.jpg");
  216. photo = "/" + photo.Substring(photo.IndexOf("Content"));
  217. }
  218. result.Photo = photo;
  219. }
  220. return Success(new { basicInfo = data, userInfo = result });
  221. }
  222. public ActionResult GetTeacherInfo()
  223. {
  224. var data = LoginUserInfo.Get();
  225. var result = empInfoIBLL.GetEmpInfoEntityByEmpNo(data.account);
  226. return Success(new { basecInfo = data, userInfo = result });
  227. }
  228. public ActionResult GetTeacherInfoById(string id)
  229. {
  230. var result = empInfoIBLL.GetEmpInfoEntityById(id);
  231. var baseInfo = userIBLL.GetEntityByAccount(result.EmpNo);
  232. var url = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  233. if (!string.IsNullOrEmpty(url))
  234. {
  235. url = "/" + url.Substring(url.IndexOf("Resource"));
  236. }
  237. return Success(new { basecInfo = baseInfo, userInfo = result, imgUrl = url });
  238. }
  239. #endregion
  240. #region 提交数据
  241. /// <summary>
  242. /// 上传头像
  243. /// </summary>
  244. /// <returns></returns>
  245. [HttpPost]
  246. public ActionResult UploadFile()
  247. {
  248. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  249. //没有文件上传,直接返回
  250. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  251. {
  252. return HttpNotFound();
  253. }
  254. UserInfo userInfo = LoginUserInfo.Get();
  255. string FileEextension = Path.GetExtension(files[0].FileName);
  256. string filePath = Config.GetValue("AnnexesFile");
  257. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  258. string fileGuid = Guid.NewGuid().ToString();
  259. string fileHeadImg = Config.GetValue("AnnexesFile");
  260. //string fullFileName = string.Format("{0}/{1}{2}", fileHeadImg, userInfo.userId, FileEextension);
  261. string fullFileName = $"{fileHeadImg}/{userInfo.userId}/{uploadDate}/{fileGuid}{FileEextension}";
  262. var saveFileName = "/Resource/" + fullFileName.Substring(fullFileName.IndexOf(userInfo.userId), fullFileName.Length - fullFileName.IndexOf(userInfo.userId));
  263. //创建文件夹,保存文件
  264. string path = Path.GetDirectoryName(fullFileName);
  265. Directory.CreateDirectory(path);
  266. files[0].SaveAs(fullFileName);
  267. UserEntity userEntity = new UserEntity();
  268. userEntity.F_UserId = userInfo.userId;
  269. userEntity.F_Account = userInfo.account;
  270. userEntity.F_HeadIcon = saveFileName;
  271. userIBLL.SaveEntity(userEntity.F_UserId, userEntity);
  272. return Success("上传成功。");
  273. }
  274. /// <summary>
  275. /// 验证旧密码
  276. /// </summary>
  277. /// <param name="OldPassword"></param>
  278. /// <returns></returns>
  279. [HttpPost]
  280. [AjaxOnly]
  281. public ActionResult ValidationOldPassword(string OldPassword)
  282. {
  283. UserInfo userInfo = LoginUserInfo.Get();
  284. var entity = userIBLL.GetEntityByUserId(userInfo.userId);
  285. OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  286. if (OldPassword != entity.F_Password)
  287. {
  288. return Fail("原密码错误,请重新输入");
  289. }
  290. else
  291. {
  292. return Success("通过信息验证");
  293. }
  294. }
  295. /// <summary>
  296. /// 提交修改密码
  297. /// </summary>
  298. /// <param name="password">新密码</param>
  299. /// <param name="oldPassword">旧密码</param>
  300. /// <param name="verifyCode">验证码</param>
  301. /// <returns></returns>
  302. [HttpPost]
  303. [AjaxOnly]
  304. public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode)
  305. {
  306. verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16);
  307. if (Session["session_verifycode"].IsEmpty() || verifyCode != Session["session_verifycode"].ToString())
  308. {
  309. return Fail("验证码错误,请重新输入");
  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. [HttpPost]
  322. [AjaxOnly]
  323. public ActionResult SubmitResetPasswordNoCode(string password, string oldPassword)
  324. {
  325. bool res = userIBLL.RevisePassword(password, oldPassword);
  326. if (!res)
  327. {
  328. return Fail("原密码错误,请重新输入");
  329. }
  330. Session.Abandon();
  331. Session.Clear();
  332. OperatorHelper.Instance.EmptyCurrent();
  333. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  334. }
  335. #endregion
  336. }
  337. }