BlWhite.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ProjectBase.Data.BaseDAL;
  7. using ProjectBase.Data.Logs;
  8. using SIMDP.DAL.IDALSQL;
  9. using SIMDP.Model;
  10. using ProjectBase.Util;
  11. namespace SIMDP.BLL
  12. {
  13. public class BlWhite : BaseBLL<MoWhite>
  14. {
  15. private IDalWhite dalBlack;
  16. /// <summary>
  17. /// 构造函数
  18. /// </summary>
  19. public BlWhite() : base()
  20. {
  21. base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
  22. dalBlack = baseDal as IDalWhite;
  23. dalBlack.OnOperationLog += new OperationLogEventHandler(BlLogOperation.OnOperationLog);
  24. }
  25. /// <summary>
  26. /// 黑白名单验证
  27. /// </summary>
  28. /// <param name="user">用户</param>
  29. /// <param name="ip">本机IP地址</param>
  30. /// <param name="message">反馈信息</param>
  31. /// <returns></returns>
  32. public bool VerifyBlackWhite(string userAccount, string ip,out string message)
  33. {
  34. try
  35. {
  36. List<MoWhite> list = Find(string.Format(" black_UserAccount = '{0}' AND black_forbid = 0", userAccount));
  37. if (list == null || list.Count == 0)
  38. {
  39. message = "";
  40. return true;
  41. }
  42. foreach (MoWhite item in list)
  43. {
  44. if (item.Type == 0 ) //黑名单
  45. {
  46. if (item.IPStart.CompareTo(ip) <= 0 && item.IPEnd.CompareTo(ip) >=0)
  47. {
  48. message = "您被黑名单禁止登录!";
  49. MoLogLogIn moLogIn = new MoLogLogIn
  50. {
  51. Account = userAccount,
  52. Name = SysEnvironment.CurrentLoginName,
  53. GroupId = SysEnvironment.CurrentLoginGroupId,
  54. Description = "用户登录操作被黑名单禁止登录!",
  55. Ip = ip,
  56. Mac = SysEnvironment.Mac,
  57. Time = DateTime.Now
  58. };
  59. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  60. return false;
  61. }
  62. }
  63. if (item.Type == 1) //白名单
  64. {
  65. if (item.IPStart.CompareTo(ip) >0 || item.IPEnd.CompareTo(ip) < 0)
  66. {
  67. message = "您被白名单禁止登录!";
  68. MoLogLogIn moLogIn = new MoLogLogIn
  69. {
  70. Account = userAccount,
  71. Name = SysEnvironment.CurrentLoginName,
  72. GroupId = SysEnvironment.CurrentLoginGroupId,
  73. Description = "用户登录操作被白名单禁止登录!",
  74. Ip = ip,
  75. Mac = SysEnvironment.Mac,
  76. Time = DateTime.Now
  77. };
  78. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  79. return false;
  80. }
  81. }
  82. }
  83. message = "";
  84. return true;
  85. }
  86. catch (Exception ex)
  87. {
  88. LogHelper.log.Error(string.Format("黑白名单验证出现错误:{0}", ex));
  89. message = ex.ToString();
  90. return false;
  91. }
  92. }
  93. }
  94. }