Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UserCenterController.cs 12 KiB

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 DepartmentIBLL departmentIBLL = new DepartmentBLL();
  26. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  27. private AnnexesFileIBLL annesexFileIBll = new AnnexesFileBLL();
  28. #region 视图功能
  29. /// <summary>
  30. /// 个人中心
  31. /// </summary>
  32. /// <returns></returns>
  33. [HttpGet]
  34. public ActionResult Index()
  35. {
  36. var baseUser = LoginUserInfo.Get();
  37. var userID = "";
  38. var checkMark = "";
  39. if (baseUser.Description == "教师")
  40. {
  41. var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode);
  42. if (teacher != null)
  43. {
  44. userID = teacher.EmpId;
  45. checkMark = teacher.CheckMark.ToString();
  46. teacher.DepartmentName= departmentIBLL.GetEntity(teacher.F_DepartmentId)?.F_FullName;
  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. result.DepartmentName = departmentIBLL.GetEntity(result.F_DepartmentId)?.F_FullName;
  229. return Success(new { basecInfo = data, userInfo = result });
  230. }
  231. public ActionResult GetTeacherInfoById(string id)
  232. {
  233. var result = empInfoIBLL.GetEmpInfoEntityById(id);
  234. var baseInfo = userIBLL.GetEntityByAccount(result.EmpNo);
  235. var url = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath;
  236. if (!string.IsNullOrEmpty(url))
  237. {
  238. url = "/" + url.Substring(url.IndexOf("Resource"));
  239. }
  240. return Success(new { basecInfo = baseInfo, userInfo = result, imgUrl = url });
  241. }
  242. #endregion
  243. #region 提交数据
  244. /// <summary>
  245. /// 上传头像
  246. /// </summary>
  247. /// <returns></returns>
  248. [HttpPost]
  249. public ActionResult UploadFile()
  250. {
  251. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  252. //没有文件上传,直接返回
  253. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  254. {
  255. return HttpNotFound();
  256. }
  257. UserInfo userInfo = LoginUserInfo.Get();
  258. string FileEextension = Path.GetExtension(files[0].FileName);
  259. string filePath = Config.GetValue("AnnexesFile");
  260. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  261. string fileGuid = Guid.NewGuid().ToString();
  262. string fileHeadImg = Config.GetValue("AnnexesFile");
  263. //string fullFileName = string.Format("{0}/{1}{2}", fileHeadImg, userInfo.userId, FileEextension);
  264. string fullFileName = $"{fileHeadImg}/{userInfo.userId}/{uploadDate}/{fileGuid}{FileEextension}";
  265. var saveFileName = "/Resource/" + fullFileName.Substring(fullFileName.IndexOf(userInfo.userId), fullFileName.Length - fullFileName.IndexOf(userInfo.userId));
  266. //创建文件夹,保存文件
  267. string path = Path.GetDirectoryName(fullFileName);
  268. Directory.CreateDirectory(path);
  269. files[0].SaveAs(fullFileName);
  270. UserEntity userEntity = new UserEntity();
  271. userEntity.F_UserId = userInfo.userId;
  272. userEntity.F_Account = userInfo.account;
  273. userEntity.F_HeadIcon = saveFileName;
  274. userIBLL.SaveEntity(userEntity.F_UserId, userEntity);
  275. return Success("上传成功。");
  276. }
  277. /// <summary>
  278. /// 验证旧密码
  279. /// </summary>
  280. /// <param name="OldPassword"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [AjaxOnly]
  284. public ActionResult ValidationOldPassword(string OldPassword)
  285. {
  286. UserInfo userInfo = LoginUserInfo.Get();
  287. var entity = userIBLL.GetEntityByUserId(userInfo.userId);
  288. OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, entity.F_Secretkey).ToLower(), 32).ToLower();
  289. if (OldPassword != entity.F_Password)
  290. {
  291. return Fail("原密码错误,请重新输入");
  292. }
  293. else
  294. {
  295. return Success("通过信息验证");
  296. }
  297. }
  298. /// <summary>
  299. /// 提交修改密码
  300. /// </summary>
  301. /// <param name="password">新密码</param>
  302. /// <param name="oldPassword">旧密码</param>
  303. /// <param name="verifyCode">验证码</param>
  304. /// <returns></returns>
  305. [HttpPost]
  306. [AjaxOnly]
  307. public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode)
  308. {
  309. verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16);
  310. if (Session["session_verifycode"].IsEmpty() || verifyCode != Session["session_verifycode"].ToString())
  311. {
  312. return Fail("验证码错误,请重新输入");
  313. }
  314. bool res = userIBLL.RevisePassword(password, oldPassword);
  315. if (!res)
  316. {
  317. return Fail("原密码错误,请重新输入");
  318. }
  319. Session.Abandon();
  320. Session.Clear();
  321. OperatorHelper.Instance.EmptyCurrent();
  322. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  323. }
  324. [HttpPost]
  325. [AjaxOnly]
  326. public ActionResult SubmitResetPasswordNoCode(string password, string oldPassword)
  327. {
  328. bool res = userIBLL.RevisePassword(password, oldPassword);
  329. if (!res)
  330. {
  331. return Fail("原密码错误,请重新输入");
  332. }
  333. Session.Abandon();
  334. Session.Clear();
  335. OperatorHelper.Instance.EmptyCurrent();
  336. return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。");
  337. }
  338. #endregion
  339. }
  340. }