using learun.iapplication; using learun.operat; using learun.util; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace EC.Web.Controllers { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.10.24 /// 描 述:个人中心 /// public class UserCenterController : MvcControllerBase { private readonly UserIBLL _userIBLL; private readonly PostIBLL _postIBLL; private readonly RoleIBLL _roleIBLL; private readonly UserRelationIBLL _userRelationIBLL; private readonly IOperator _operator; public UserCenterController(UserIBLL userIBLL, PostIBLL postIBLL, RoleIBLL roleIBLL, UserRelationIBLL userRelationIBLL, IOperator ioperator) { _userIBLL = userIBLL; _postIBLL = postIBLL; _roleIBLL = roleIBLL; _userRelationIBLL = userRelationIBLL; _operator = ioperator; } #region 视图功能 /// /// 个人中心 /// /// [HttpGet] public IActionResult Index() { return View(); } /// /// 联系方式 /// /// [HttpGet] public IActionResult ContactForm() { return View(); } /// /// 上传头像 /// /// [HttpGet] public IActionResult HeadForm() { return View(); } /// /// 修改密码 /// /// [HttpGet] public IActionResult PassWordForm() { return View(); } /// /// 个人中心-日志管理 /// /// [HttpGet] public IActionResult LogIndex() { return View(); } #endregion 视图功能 #region 获取数据 [HttpGet] [AjaxOnly] public async Task GetUserInfo() { var data = await CurrentUser(); data.F_Password = null; data.F_Secretkey = null; var roleIds = await _userRelationIBLL.GetObjectIds(data.F_UserId, 1); var postIds = await _userRelationIBLL.GetObjectIds(data.F_UserId, 2); var jsonData = new { baseinfo = data, post = await _postIBLL.GetListByPostIds(postIds), role = await _roleIBLL.GetListByRoleIds(roleIds) }; return Success(jsonData); } #endregion 获取数据 #region 提交数据 /// /// 验证旧密码 /// /// /// [HttpPost] [AjaxOnly] public async Task ValidationOldPassword(string OldPassword) { var userInfo = await CurrentUser(); OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, userInfo.F_Secretkey).ToLower(), 32).ToLower(); if (OldPassword != userInfo.F_Password) { return Fail("原密码错误,请重新输入"); } else { return SuccessInfo("通过信息验证"); } } /// /// 提交修改密码 /// /// 新密码 /// 旧密码 /// [HttpPost] [AjaxOnly] public async Task SubmitResetPassword(string password, string oldPassword) { var userInfo = await CurrentUser(); if (userInfo.F_SecurityLevel == 1) { return Fail("当前账户不能修改密码"); } bool res = await _userIBLL.RevisePassword(password, oldPassword); if (!res) { return Fail("原密码错误,请重新输入"); } return SuccessInfo("密码修改成功,请牢记新密码。\r 将会自动安全退出。"); } #endregion 提交数据 } }