/// <summary> /// 写入日志 /// </summary> /// <param name="action">动作</param> public static void WriteLogActions(string action) { if (IsMemberLogin()) { string LogId = SessionHelper.GetSession(KEY_C_LOGID).ToString(); if (string.IsNullOrEmpty(LogId)) { LogId = CookiesHelper.GetCookie(KEY_C_LOGID);//日志GUID } if (!string.IsNullOrEmpty(LogId)) { MemberLog log = MemberLog.FindByGUID(LogId); if (log != null) { log.Actions = log.Actions + action; log.LastUpdateTime = DateTime.Now; log.Update(); } } } }
/// <summary> /// 会员登录 /// </summary> /// <param name="userName">用户名,用户ID或者用户Email</param> /// <param name="passWord"></param> /// <returns></returns> public static bool MemberLogin(String userName, String passWord) { bool flag = false; if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord)) { return(false); } userName = userName.Trim(); Member entity = new Member(); Guid GUID = Guid.NewGuid(); MemberLog log = new MemberLog(); log.GUID = GUID.ToString(); log.IsLoginOK = 0; log.PassWord = passWord.Trim(); log.LoginIP = Utils.GetIP(); log.UId = 0; log.LoginTime = DateTime.Now; log.UserName = userName.Trim(); log.LastUpdateTime = DateTime.Now; //if (Utils.IsInt(userName) && !Utils.IsTel(userName))//使用UID登录 //{ // //如果数字过大,则用用户名登录 // if (userName.Length > 8) // entity = Member.Find(Member._.UserName == userName); // else // { // entity = Member.Find(_.Id, int.Parse(userName)); // if (entity == null) // entity = Find(Member._.UserName == userName); // } //} //else if (Utils.IsTel(userName)) //{ // entity = Member.Find(_.Tel == userName); //} //else if (Utils.IsValidEmail(userName)) //{ // entity = Member.Find(_.Email, userName); //} //else //{ // entity = Member.Find(_.UserName, userName); //} entity = Member.Find(Member._.UserName == userName); if (entity != null && entity.PassWord == Utils.MD5(entity.Salt + passWord.Trim())) { entity.LoginCount += 1; entity.LastLoginIP = entity.ThisLoginIP; entity.LastLoginTime = entity.ThisLoginTime; entity.ThisLoginIP = Utils.GetIP(); entity.ThisLoginTime = DateTime.Now; entity.Update(); //记录 log.UId = entity.Id; log.IsLoginOK = 1; log.PassWord = "******"; log.Actions = "用户登录成功。"; log.Insert(); SetUserInfo(entity.UserName, entity.PassWord, entity.Id, 60 * 2, entity.Salt, GUID.ToString()); flag = true; } else { log.Actions = "登录失败:用户名或者密码错误。"; log.Insert(); } return(flag); }