using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectBase.Data.BaseDAL; using ProjectBase.Data.Logs; using SIMDP.DAL.IDALSQL; using SIMDP.Model; using ProjectBase.Util; namespace SIMDP.BLL { public class BlWhite : BaseBLL { private IDalWhite dalBlack; /// /// 构造函数 /// public BlWhite() : base() { base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); dalBlack = baseDal as IDalWhite; dalBlack.OnOperationLog += new OperationLogEventHandler(BlLogOperation.OnOperationLog); } /// /// 黑白名单验证 /// /// 用户 /// 本机IP地址 /// 反馈信息 /// public bool VerifyBlackWhite(string userAccount, string ip,out string message) { try { List list = Find(string.Format(" black_UserAccount = '{0}' AND black_forbid = 0", userAccount)); if (list == null || list.Count == 0) { message = ""; return true; } foreach (MoWhite item in list) { if (item.Type == 0 ) //黑名单 { if (item.IPStart.CompareTo(ip) <= 0 && item.IPEnd.CompareTo(ip) >=0) { message = "您被黑名单禁止登录!"; MoLogLogIn moLogIn = new MoLogLogIn { Account = userAccount, Name = SysEnvironment.CurrentLoginName, GroupId = SysEnvironment.CurrentLoginGroupId, Description = "用户登录操作被黑名单禁止登录!", Ip = ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); return false; } } if (item.Type == 1) //白名单 { if (item.IPStart.CompareTo(ip) >0 || item.IPEnd.CompareTo(ip) < 0) { message = "您被白名单禁止登录!"; MoLogLogIn moLogIn = new MoLogLogIn { Account = userAccount, Name = SysEnvironment.CurrentLoginName, GroupId = SysEnvironment.CurrentLoginGroupId, Description = "用户登录操作被白名单禁止登录!", Ip = ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); return false; } } } message = ""; return true; } catch (Exception ex) { LogHelper.log.Error(string.Format("黑白名单验证出现错误:{0}", ex)); message = ex.ToString(); return false; } } } }