public bool Add(RoadFlow.Data.Model.Users user, Guid uniqueID) { if (user == null) { return(false); } List <RoadFlow.Data.Model.OnlineUsers> all = GetAll(); bool flag = false; RoadFlow.Data.Model.OnlineUsers onlineUsers = all.Find((RoadFlow.Data.Model.OnlineUsers p) => p.ID == user.ID); if (onlineUsers == null) { flag = true; onlineUsers = new RoadFlow.Data.Model.OnlineUsers(); RoadFlow.Data.Model.UsersRelation mainByUserID = new UsersRelation().GetMainByUserID(user.ID); if (mainByUserID != null) { onlineUsers.OrgName = new Organize().GetAllParentNames(mainByUserID.OrganizeID); } } onlineUsers.ID = user.ID; onlineUsers.ClientInfo = "操作系统:" + Tools.GetOSName() + " 浏览器:" + Tools.GetBrowse(); onlineUsers.IP = Tools.GetIPAddress(); onlineUsers.LastPage = ""; onlineUsers.LoginTime = DateTimeNew.Now; onlineUsers.UniqueID = uniqueID; onlineUsers.UserName = user.Name; if (flag) { all.Add(onlineUsers); } set(all); return(true); }
public string CheckLogin() { string name = Keys.SessionKeys.IsValidateCode.ToString(); string name2 = Keys.SessionKeys.ValidateCode.ToString(); string text = base.Request.Form["Account"]; string text2 = base.Request.Form["Password"]; string text3 = base.Request.Form["VCode"]; string b = base.Request.Form["Force"]; string str = "(帐号:" + text + " 密码:" + text2 + " 验证码:" + text3 + ")"; if (text.IsNullOrEmpty() || text2.IsNullOrEmpty()) { RoadFlow.Platform.Log.Add("用户登录失败(帐号或密码为空)" + str, "", RoadFlow.Platform.Log.Types.用户登录); return("{\"status\":0,\"msg\":\"帐号或密码不能为空!\"}"); } if (base.Session[name] != null && "1" == base.Session[name].ToString() && (base.Session[name2] == null || string.Compare(base.Session[name2].ToString(), text3.Trim1(), true) != 0)) { RoadFlow.Platform.Log.Add("用户登录失败(验证码错误)" + str, "", RoadFlow.Platform.Log.Types.用户登录); return("{\"status\":0,\"msg\":\"验证码错误!\"}"); } RoadFlow.Platform.Users users = new RoadFlow.Platform.Users(); RoadFlow.Data.Model.Users byAccount = users.GetByAccount(text.Trim()); if (byAccount == null || string.Compare(byAccount.Password, users.GetUserEncryptionPassword(byAccount.ID.ToString(), text2.Trim()), false) != 0) { base.Session[name] = "1"; RoadFlow.Platform.Log.Add("用户登录失败(帐号或密码错误)" + str, "", RoadFlow.Platform.Log.Types.用户登录); return("{\"status\":0,\"msg\":\"帐号或密码错误!\"}"); } if (byAccount.Status == 1) { base.Session[name] = "1"; RoadFlow.Platform.Log.Add("用户登录失败(帐号已被冻结)" + str, "", RoadFlow.Platform.Log.Types.用户登录); return("{\"status\":0,\"msg\":\"帐号已被冻结!\"}"); } RoadFlow.Platform.OnlineUsers onlineUsers = new RoadFlow.Platform.OnlineUsers(); RoadFlow.Data.Model.OnlineUsers onlineUsers2 = onlineUsers.Get(byAccount.ID); if (onlineUsers2 != null && "1" != b) { string iP = onlineUsers2.IP; base.Session.Remove(name); return("{\"status\":2,\"msg\":\"当前帐号已经在" + iP + "登录,您要强行登录吗?\"}"); } Guid guid = Guid.NewGuid(); base.Session[Keys.SessionKeys.UserID.ToString()] = byAccount.ID; base.Session[Keys.SessionKeys.UserUniqueID.ToString()] = guid; base.Session[Keys.SessionKeys.BaseUrl.ToString()] = base.Url.Content("~/"); base.Session[Keys.SessionKeys.UserName.ToString()] = byAccount.Name; base.Response.Cookies.Add(new HttpCookie(Keys.SessionKeys.UserID.ToString(), byAccount.ID.ToString()) { Expires = MyController.CurrentDateTime.AddDays(7.0) }); onlineUsers.Add(byAccount, guid); base.Session.Remove(name); RoadFlow.Platform.Log.Add("用户登录成功(帐号:" + text + ")", "", RoadFlow.Platform.Log.Types.用户登录); return("{\"status\":1,\"msg\":\"成功!\"}"); }
public bool Remove(Guid userID) { List <RoadFlow.Data.Model.OnlineUsers> all = GetAll(); RoadFlow.Data.Model.OnlineUsers onlineUsers = all.Find((RoadFlow.Data.Model.OnlineUsers p) => p.ID == userID); if (onlineUsers != null) { all.Remove(onlineUsers); } set(all); return(true); }