123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<MoWhite>
- {
- private IDalWhite dalBlack;
- /// <summary>
- /// 构造函数
- /// </summary>
- public BlWhite() : base()
- {
- base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
- dalBlack = baseDal as IDalWhite;
- dalBlack.OnOperationLog += new OperationLogEventHandler(BlLogOperation.OnOperationLog);
- }
- /// <summary>
- /// 黑白名单验证
- /// </summary>
- /// <param name="user">用户</param>
- /// <param name="ip">本机IP地址</param>
- /// <param name="message">反馈信息</param>
- /// <returns></returns>
- public bool VerifyBlackWhite(string userAccount, string ip,out string message)
- {
- try
- {
- List<MoWhite> 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<BlLogLogIn>.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<BlLogLogIn>.Instance.Insert(moLogIn);
- return false;
- }
- }
- }
- message = "";
- return true;
- }
- catch (Exception ex)
- {
- LogHelper.log.Error(string.Format("黑白名单验证出现错误:{0}", ex));
- message = ex.ToString();
- return false;
- }
- }
- }
- }
|