예제 #1
0
 /// <summary>
 /// 用于向 SysUserLoginLog EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToSysUserLoginLog(SysUserLoginLog sysUserLoginLog)
 {
     base.AddObject("SysUserLoginLog", sysUserLoginLog);
 }
예제 #2
0
 /// <summary>
 /// 创建新的 SysUserLoginLog 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 /// <param name="userName">UserName 属性的初始值。</param>
 /// <param name="iPAddress">IPAddress 属性的初始值。</param>
 /// <param name="macAddress">MacAddress 属性的初始值。</param>
 /// <param name="hostName">HostName 属性的初始值。</param>
 /// <param name="loginTime">LoginTime 属性的初始值。</param>
 /// <param name="loginState">LoginState 属性的初始值。</param>
 public static SysUserLoginLog CreateSysUserLoginLog(global::System.Int32 id, global::System.String userName, global::System.String iPAddress, global::System.String macAddress, global::System.String hostName, global::System.DateTime loginTime, global::System.String loginState)
 {
     SysUserLoginLog sysUserLoginLog = new SysUserLoginLog();
     sysUserLoginLog.ID = id;
     sysUserLoginLog.UserName = userName;
     sysUserLoginLog.IPAddress = iPAddress;
     sysUserLoginLog.MacAddress = macAddress;
     sysUserLoginLog.HostName = hostName;
     sysUserLoginLog.LoginTime = loginTime;
     sysUserLoginLog.LoginState = loginState;
     return sysUserLoginLog;
 }
예제 #3
0
        /// <summary>
        /// 登陆
        /// </summary>
        public static SysUser Login(string macAddress, string ipAddress, string hostName)
        {
            try
            {
                UserNamePasswordValidator validator = (UserNamePasswordValidator)OperationContext.Current.Host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator;
                LDLLogisticsEntities context = new LDLLogisticsEntities();
                SysUserLoginLog log = new SysUserLoginLog();
                log.MacAddress = macAddress;
                log.IPAddress = ipAddress;
                log.HostName = hostName;
                log.LoginTime = DateTime.Now;
                log.UserName = validator.CurrentUser.UserName;
                log.LoginState = "成功";
                context.SysUserLoginLog.AddObject(log);

                if (validator.CurrentUser.CheckComputer)
                {
                    string computerCode = SecurityHelper.MD5(macAddress + "|" + hostName);
                    if (!validator.CurrentUser.ComputerCode.Contains(computerCode))
                    {
                        log.LoginState = "失败";
                        context.SaveChanges();
                        throw new FaultException("请在指定的计算机上登陆!");
                    }
                }
                context.SaveChanges();
                return validator.CurrentUser;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }