using Learun.Application.Base.SystemModule; using Learun.Application.Organization; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Util; using Learun.Util.Operat; using System; using System.IO; using System.Web; using System.Web.Mvc; namespace Learun.Application.Web.Controllers { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.07 /// 描 述:个人中心 /// public class UserCenterController : MvcControllerBase { private UserIBLL userIBLL = new UserBLL(); private PostIBLL postIBLL = new PostBLL(); private RoleIBLL roleIBLL = new RoleBLL(); private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL(); private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL(); private AnnexesFileIBLL annesexFileIBll = new AnnexesFileBLL(); #region 视图功能 /// /// 个人中心 /// /// [HttpGet] public ActionResult Index() { var baseUser = LoginUserInfo.Get(); var userID = ""; var checkMark = ""; if (baseUser.Description == "教师") { var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode); if (teacher != null) { userID = teacher.EmpId; checkMark = teacher.CheckMark.ToString(); } } else if (baseUser.Description == "学生") { var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode); if (student != null) { userID = student.StuId; checkMark = student.CheckMark?.ToString(); } } ViewBag.UserType = baseUser.Description; ViewBag.UserID = userID; ViewBag.isCheck = checkMark; return View(); } [HttpGet] public ActionResult IndexForDC() { var baseUser = LoginUserInfo.Get(); var userID = ""; var checkMark = ""; if (baseUser.Description == "教师") { var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode); if (teacher != null) { userID = teacher.EmpId; checkMark = teacher.CheckMark.ToString(); } } else if (baseUser.Description == "学生") { var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode); if (student != null) { userID = student.StuId; checkMark = student.CheckMark?.ToString(); } } ViewBag.UserType = baseUser.Description; ViewBag.UserID = userID; ViewBag.isCheck = checkMark; return View(); } /// /// 联系方式 /// /// [HttpGet] public ActionResult ContactForm() { return View(); } /// /// 上传头像 /// /// [HttpGet] public ActionResult HeadForm() { return View(); } /// /// 修改密码 /// /// [HttpGet] public ActionResult PassWordForm() { return View(); } /// /// 个人中心-日志管理 /// /// [HttpGet] public ActionResult LogIndex() { return View(); } /// /// 个人中心 /// /// [HttpGet] public ActionResult IndexInTeacher() { var baseUser = LoginUserInfo.Get(); var userID = ""; var checkMark = ""; if (baseUser.Description == "教师") { var teacher = empInfoIBLL.GetEmpInfoEntityByEmpNo(baseUser.enCode); if (teacher != null) { userID = teacher.EmpId; checkMark = teacher.CheckMark.ToString(); } } else if (baseUser.Description == "学生") { var student = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(baseUser.enCode); if (student != null) { userID = student.StuId; checkMark = student.CheckMark?.ToString(); } } ViewBag.UserType = baseUser.Description; ViewBag.UserID = userID; ViewBag.isCheck = checkMark; return View(); } /// /// 个人中心-语言设置 /// /// [HttpGet] public ActionResult LanguageForm() { return View(); } #endregion #region 获取数据 /// /// 生成验证码 /// /// [HttpGet] public ActionResult VerifyCode() { return File(new VerifyCode().GetVerifyCode(), @"image/Gif"); } [HttpGet] [AjaxOnly] public ActionResult GetUserInfo() { var data = LoginUserInfo.Get(); data.password = null; data.secretkey = null; var jsonData = new { baseinfo = data, post = postIBLL.GetListByPostIds(data.postIds), role = roleIBLL.GetListByRoleIds(data.roleIds) }; return JsonResult(jsonData); } public ActionResult GetStudentInfo(string stuId = null) { var data = LoginUserInfo.Get(); var result = new StuInfoBasicEntity(); if (stuId != null) { result = stuInfoBasicIBLL.GetStuInfoBasicEntity(stuId); } else { result = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(data.account); } if (result != null) { var photo = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath; if (photo != null) { photo = "/" + photo.Substring(photo.IndexOf("Resource")); } else { photo = Config.GetValue("fileHeadImg") +"/"+ (result.GenderNo==true? "on-boy.jpg" : "on-girl.jpg"); photo = "/" + photo.Substring(photo.IndexOf("Content")); } result.Photo = photo; } return Success(new { basicInfo = data, userInfo = result }); } public ActionResult GetTeacherInfo() { var data = LoginUserInfo.Get(); var result = empInfoIBLL.GetEmpInfoEntityByEmpNo(data.account); return Success(new { basecInfo = data, userInfo = result }); } public ActionResult GetTeacherInfoById(string id) { var result = empInfoIBLL.GetEmpInfoEntityById(id); var baseInfo = userIBLL.GetEntityByAccount(result.EmpNo); var url = annesexFileIBll.GetEntityByFolderId(result.Photo)?.F_FilePath; if (!string.IsNullOrEmpty(url)) { url = "/" + url.Substring(url.IndexOf("Resource")); } return Success(new { basecInfo = baseInfo, userInfo = result, imgUrl = url }); } #endregion #region 提交数据 /// /// 上传头像 /// /// [HttpPost] public ActionResult UploadFile() { HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; //没有文件上传,直接返回 if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName)) { return HttpNotFound(); } UserInfo userInfo = LoginUserInfo.Get(); string FileEextension = Path.GetExtension(files[0].FileName); string filePath = Config.GetValue("AnnexesFile"); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string fileGuid = Guid.NewGuid().ToString(); string fileHeadImg = Config.GetValue("AnnexesFile"); //string fullFileName = string.Format("{0}/{1}{2}", fileHeadImg, userInfo.userId, FileEextension); string fullFileName = $"{fileHeadImg}/{userInfo.userId}/{uploadDate}/{fileGuid}{FileEextension}"; var saveFileName = "/Resource/" + fullFileName.Substring(fullFileName.IndexOf(userInfo.userId), fullFileName.Length - fullFileName.IndexOf(userInfo.userId)); //创建文件夹,保存文件 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); files[0].SaveAs(fullFileName); UserEntity userEntity = new UserEntity(); userEntity.F_UserId = userInfo.userId; userEntity.F_Account = userInfo.account; userEntity.F_HeadIcon = saveFileName; userIBLL.SaveEntity(userEntity.F_UserId, userEntity); return Success("上传成功。"); } /// /// 验证旧密码 /// /// /// [HttpPost] [AjaxOnly] public ActionResult ValidationOldPassword(string OldPassword) { UserInfo userInfo = LoginUserInfo.Get(); var entity = userIBLL.GetEntityByUserId(userInfo.userId); OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, entity.F_Secretkey).ToLower(), 32).ToLower(); if (OldPassword != entity.F_Password) { return Fail("原密码错误,请重新输入"); } else { return Success("通过信息验证"); } } /// /// 提交修改密码 /// /// 新密码 /// 旧密码 /// 验证码 /// [HttpPost] [AjaxOnly] public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode) { verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16); if (Session["session_verifycode"].IsEmpty() || verifyCode != Session["session_verifycode"].ToString()) { return Fail("验证码错误,请重新输入"); } bool res = userIBLL.RevisePassword(password, oldPassword); if (!res) { return Fail("原密码错误,请重新输入"); } Session.Abandon(); Session.Clear(); OperatorHelper.Instance.EmptyCurrent(); return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。"); } [HttpPost] [AjaxOnly] public ActionResult SubmitResetPasswordNoCode(string password, string oldPassword) { bool res = userIBLL.RevisePassword(password, oldPassword); if (!res) { return Fail("原密码错误,请重新输入"); } Session.Abandon(); Session.Clear(); OperatorHelper.Instance.EmptyCurrent(); return Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。"); } #endregion } }