using Competition.Common.Util; using CompetitionAPI.api.back; using CompetitionAPI.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace CompetitionAPI.Controllers.back.system { [Route("api/[controller]")] [ApiController] public class EditUserMimController : Controller { Competition.Mysql.BLL.admin_user user_bll = new Competition.Mysql.BLL.admin_user(); public EditUserMimController() { } /// /// 编辑用户密码接口 /// /// 请求参数 /// [Authorize] [HttpPost] [APIFilter] public JsonResult Index([FromBody] EditUserMimRequest req) { try { if (req != null) { if (string.IsNullOrEmpty(req.UserId)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "用户id不能为空")); } if (string.IsNullOrEmpty(req.NewPassWord)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "新密码不能为空")); } var model = user_bll.GetModel(req.UserId); if (model != null) { var value = RSAHelper.DecryptData(req.NewPassWord); var pwd = EncryptionAndDecryption.EncryptByLgzn(value); model.password = EncryptionAndDecryption.EncryptByLgzn(pwd); if (user_bll.Update(model)) { return Json(Tool.GetJsonWithCode(APICode.Success, "编辑成功")); } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "编辑失败")); } } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "用户数据不存在")); } } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "请求参数不能为空")); } } catch (Exception ex) { LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace); return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。")); } } } }