LoginUserEditPwdBLL.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using WMS.BZModels.Models.UserCenterManager;
  8. using WMS.Info;
  9. using WMS.BZSqlSugar;
  10. using WMS.Util;
  11. namespace WMS.BZServices.BLL
  12. {
  13. public class BZLoginUserEditPwdBLL : IBLL
  14. {
  15. private static Repository<AclUserInfo> _acluserInfoRepository => new Repository<AclUserInfo>();
  16. public object OutObjData { get; set; }
  17. public string SuccessMsg { get; set; } = "用户密码修改成功。";
  18. public LoginUserInfo LoginUser { get; set; }
  19. public string InJsonData { get; set; }
  20. public string BLLDesc { get; private set; } = "用户密码过期修改。";
  21. public void Exec()
  22. {
  23. try
  24. {
  25. void action()
  26. {
  27. LoginUserEditPwdInfo indata = InJsonData.ToObject<LoginUserEditPwdInfo>();
  28. if (indata == null)
  29. {
  30. throw BZSysExCore.ThrowInEmpty();
  31. }
  32. if (string.IsNullOrWhiteSpace(indata.TextU))
  33. {
  34. throw BZSysExCore.ThrowFailException("用户名为空。");
  35. }
  36. if (string.IsNullOrWhiteSpace(indata.TextOP))
  37. {
  38. throw BZSysExCore.ThrowFailException("旧密码为空。");
  39. }
  40. if (string.IsNullOrWhiteSpace(indata.TextNP))
  41. {
  42. throw BZSysExCore.ThrowFailException("新密码为空。");
  43. }
  44. if (indata.TextOP == indata.TextNP)
  45. {
  46. throw BZSysExCore.ThrowFailException("旧密码与新密码相同,请重新输入。");
  47. }
  48. bool tag = ValidUtil.IsPasswordOne(indata.TextNP);
  49. if (!tag)
  50. {
  51. throw BZSysExCore.ThrowFailException("新密码格式不对,需输入6-25位包含特殊字符。");
  52. }
  53. //获取数据
  54. var user=_acluserInfoRepository.Queryable().Where(it => it.Code.ToUpper() == indata.TextU.ToUpper()).First();
  55. //ACL_USERITEM user = Ctx.Queryable<ACL_USERITEM>().Where(it => it.F_NO.ToUpper() == indata.TextU.ToUpper()).First();
  56. if (user == null)
  57. throw BZSysExCore.ThrowFailException("无法找到指定用户");
  58. if (user.IsStop > 0)
  59. throw BZSysExCore.ThrowFailException("用户已停用!!!");
  60. //用户密码已过期
  61. //if (user.F_AUTOSTOPTIME.ToString("yyyy-MM-dd") != DateTime.MaxValue.ToString("yyyy-MM-dd"))
  62. //{
  63. // if (user.F_AUTOSTOPTIME < DateTime.Now)
  64. // throw BZSysExCore.ThrowFailException("用户已过期!!!");
  65. //}
  66. //if (user.F_PWDERRQTY >= SysSetCore.GetSysSet().UserPwdErrQty)
  67. // throw BZSysExCore.ThrowFailException(string.Format("用户密码错误已超过{0}次,已被锁定。", SysSetCore.GetSysSet().UserPwdErrQty));
  68. ////用户密码已过期
  69. //if (user.F_EDITPWDTIME != DateTime.MaxValue)
  70. //{
  71. // if (user.F_EDITPWDTIME.AddDays(SysSetCore.GetSysSet().UserPwdExpD) < DateTime.Now)
  72. // throw BZSysExCore.ThrowLoginTimeout();
  73. //}
  74. //用户密码错误
  75. if (user.Pwd != SysSecurityHelp.Aes256Encrypt(indata.TextOP, user.Secretkey))
  76. {
  77. int qty = 5 - user.PwdErrQty;
  78. if (user.PwdErrQty > 0)
  79. throw new BZSysExCore(ESysExType.PwdError, string.Format("用户密码错误,您还有{0}次", qty > 0 ? qty : 0));
  80. else
  81. throw new BZSysExCore(ESysExType.PwdError, "用户密码错误。");
  82. }
  83. _acluserInfoRepository.UpdateModelColumns(p => new AclUserInfo
  84. {
  85. Pwd = SysSecurityHelp.Aes256Encrypt(indata.TextNP, user.Secretkey),
  86. EditWho = user.Code,
  87. EditTime = DateTime.Now,
  88. PwdEditTime = DateTime.Now,
  89. PwdErrQty = 0
  90. }, it => it.Code.ToUpper() == user.Code.ToUpper());
  91. }
  92. _acluserInfoRepository.LoginUseTran(action);
  93. }
  94. catch (Exception ex)
  95. {
  96. throw ex;
  97. }
  98. }
  99. }
  100. }