public void AddLoginLog(UserType userType, string strUserName, bool isLogined) { LoginLogInfo last = LoginLog.GetLast(userType, strUserName); LoginLogInfo entity = new LoginLogInfo { UserType = userType.ToString(), UserName = strUserName, IPAddress = IPUtils.GetIP(), IPArea = ((userType == UserType.Manager) ? IPUtils.GetIPAreaFromPcOnline(IPUtils.GetIP()) : string.Empty), LoginStatus = (isLogined ? 1 : 0), LoginFailCount = ((!isLogined) ? ((last == null) ? 1 : (last.LoginFailCount + 1)) : 0), Lang = JObject.cultureLang, AutoTimeStamp = DateTime.Now }; LoginLog.Add(entity); }
public static LoginLogInfo GetLast(string strUserName) { return(LoginLog.GetLast(UserType.Manager, strUserName)); }
public static LoginStatus UserLogin(string strLoginName, string strEncryPassword, ref UserInfo userRef) { SqlParameter[] arrParam = new SqlParameter[] { new SqlParameter("@loginname", strLoginName) }; userRef = BizBase.dbo.GetModel <UserInfo>(BizBase.dbo.ExecProcReReader("p_System_UserLogin", arrParam)); LoginLogInfo last = LoginLog.GetLast(UserType.User, strLoginName); LoginStatus result; if (userRef == null) { result = LoginStatus.UserNameIncorrect; } else if (last != null && last.LoginFailCount >= ConfigProvider.Configs.TryLoginTimes && (DateTime.Now - last.AutoTimeStamp).TotalMinutes < 5.0) { result = LoginStatus.MutilLoginFail; } else if (strEncryPassword != userRef.Password) { new LogManager().AddLoginLog(UserType.User, strLoginName, false); result = LoginStatus.PasswordIncorrect; } else if (userRef.Status != 99) { result = LoginStatus.StatusNotAllow; } else { HttpCookie httpCookie = new HttpCookie("singoouser"); httpCookie.Values["uid"] = userRef.AutoID.ToString(); httpCookie.Values["uname"] = HttpUtility.UrlEncode(userRef.UserName); httpCookie.Values["nickname"] = HttpUtility.UrlEncode(userRef.NickName); httpCookie.Values["pwd"] = HttpUtility.UrlEncode(DEncryptUtils.DESEncode(userRef.Password)); string cookieTime = ConfigProvider.Configs.CookieTime; if (cookieTime != null) { if (!(cookieTime == "一周")) { if (cookieTime == "一年") { httpCookie.Expires = DateTime.Now.AddYears(1); } } else { httpCookie.Expires = DateTime.Now.AddDays(7.0); } } HttpContext.Current.Response.Cookies.Add(httpCookie); userRef.LoginCount++; userRef.LastLoginIP = IPUtils.GetIP(); userRef.LastLoginTime = DateTime.Now; if (string.IsNullOrEmpty(userRef.Province)) { TaoBaoAreaInfo iPAreaFromTaoBao = IPUtils.GetIPAreaFromTaoBao(IPUtils.GetIP()); if (iPAreaFromTaoBao != null) { userRef.Country = iPAreaFromTaoBao.data.country; userRef.Province = iPAreaFromTaoBao.data.region; userRef.City = iPAreaFromTaoBao.data.city; userRef.County = iPAreaFromTaoBao.data.county; } } User.Update(userRef); new LogManager().AddLoginLog(UserType.User, strLoginName, true); result = LoginStatus.Success; } return(result); }