LoginUserEditPwdBLL.cs 4.8 KB

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