public ActionResult DeleteSysMsg(DateTime date) { string SysKey = MyRedisKeys.Pre_SysMsg + CurrentUser.ID; SysMsg msg = MyRedisDB.GetSet <SysMsg>(SysKey).Where(s => s.Date.ToString("yyyyMMddHHmmss") == date.ToString("yyyyMMddHHmmss")).FirstOrDefault(); MyRedisDB.SetRemove(SysKey, msg); return(Json(new { msg = "done" })); }
public BaseResponse <BaseResponseList <SysMsg> > searchMsgList(VMMsgSearchMsgRequest condtion) { BaseResponse <BaseResponseList <SysMsg> > result = new BaseResponse <BaseResponseList <SysMsg> >(); try { result.result = SysMsg.searchLog(condtion); } catch (Exception e) { SysException.getResult(result, e, condtion); } return(result); }
public ActionResult NewBeeDelete(Guid id) { NewBee newBee = NewBeeDataSvc.GetByID(id); NewBeeDataSvc.DeleteByID(id); SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的" + Enum.GetName(typeof(EnumObjectType), 2) + "被删除"; msg.Msg = newBee.Title.MaxByteLength(30); string key = MyRedisKeys.Pre_SysMsg + newBee.OwnerID; MyRedisDB.SetAdd(key, msg); return(Json(new { msg = "done" })); }
public async Task <IActionResult> FtpUpload(List <IFormFile> files) { var ids = new List <int>(); foreach (var formFile in files) { if (formFile.Length > 0) { var ftpFileName = Path.GetRandomFileName(); await UploadFileExample.UploadFileAsync2(formFile.OpenReadStream(), ftpFileName, UploadFileExample.FTP_DEFAULT_PATH); int id = SaveFileInfo(formFile.FileName, formFile.ContentType, ftpFileName, UploadFileExample.FTP_DEFAULT_PATH); ids.Add(id); } } return(Ok(SysMsg.Success("图片上传成功!", ids))); }
public ActionResult UserOperate(string type, Guid uid, int objectType, int days = 0) { if (type == "启") { DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault(); MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du); SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的账号已解封"; msg.Msg = "你的账号在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块中已解封"; string key = MyRedisKeys.Pre_SysMsg + uid; MyRedisDB.SetAdd(key, msg); } else { DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault(); if (du == null) { du = new DisabledUser(); du.UserID = uid; du.ObjectType = objectType; du.AbleDate = DateTime.Now.AddDays(days); MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du); } else { MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du); du.AbleDate = DateTime.Now.AddDays(days); MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du); } SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的账号被封禁"; msg.Msg = "你在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块被封禁至" + du.AbleDate.ToString("yyyy-MM-dd HH:mm"); string key = MyRedisKeys.Pre_SysMsg + uid; MyRedisDB.SetAdd(key, msg); } return(Json(new { msg = "done" })); }
public bool UserLogin(string id, string pwd) { bool b = false; ProtocolChat protocolChat1 = new ProtocolChat(); protocolChat1.model = 1; protocolChat1.ope = 2; UserInfo userInfo = new UserInfo(); userInfo.Name = id; userInfo.Pwd = pwd; protocolChat1.data = userInfo; //向服务器发消息 this.Send(protocolChat1); //接受服务器消息 var protocolChat2 = this.Receive(); if (protocolChat2.model == 1 && protocolChat2.ope == 2) { SysMsg sysmsg = protocolChat2.data as SysMsg; if (sysmsg.Type == 0) { //登录成功! b = true; this.myName = id; //用户名字 this.flag = true; //创建线程 Thread threadHandlingMsg = new Thread(this.HandlingMsg); //设置为后台线程 threadHandlingMsg.IsBackground = true; //启动线程 threadHandlingMsg.Start(); } } return(b); }
//添加用户或更新用户信息 public bool UpdateUserInfo(string loginType, string token) { if (loginType == "github") { GitHubUser githubUser = GitHub.GetGitHubUser(token); if (githubUser.id == 0) { return(false); } NullUser user = NullUserDataSvc.GetByCondition(u => u.GitHubID == githubUser.id).FirstOrDefault(); if (user == null) { user = new NullUser(); user.LoginType = "github"; user.GitHubAccessToken = token; user.Name = githubUser.name; user.AvatarUrl = githubUser.avatar_url; user.GitHubLogin = githubUser.login; user.GitHubID = githubUser.id; user.Role = (int)EnumUserRole.普通; user.Email = githubUser.email; user.FollowingCount = githubUser.following; user.FollowerCount = githubUser.followers; NullUserDataSvc.Add(user); //用关注人数小于500的机器人账号关注普通用户 if (user.Email == null || (user.Email != null && !user.Email.EndsWith("objnull.com"))) { List <NullUser> robots = NullUserDataSvc.GetByCondition(u => u.Email.EndsWith("objnull.com") && u.GitHubLogin.Contains("robot")).ToList(); //检查是否已关注 bool followed = false; GitHubClient github = new GitHubClient(new ProductHeaderValue("objnulldotcom")); foreach (NullUser robot in robots) { github.Credentials = new Credentials(robot.GitHubAccessToken); if (github.User.Followers.IsFollowing(robot.GitHubLogin, user.GitHubLogin).Result) { followed = true; break; } } //关注 if (!followed) { NullUser frobot = robots.Where(r => r.FollowingCount < 500).First(); github.Credentials = new Credentials(frobot.GitHubAccessToken); github.User.Get(frobot.GitHubLogin); github.User.Followers.Follow(user.GitHubLogin); frobot.FollowingCount += 1; NullUserDataSvc.Update(frobot); } } if (string.IsNullOrEmpty(user.Email)) { SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "您还未设置邮箱"; msg.Msg = "请到<a href=\"/Home/UserProfile\">我的主页</a>设置或修改<a href=\"https://github.com/settings/profile\" target=\"_blank\">GitHub</a>邮箱显示后更新账号。"; string key = MyRedisKeys.Pre_SysMsg + user.ID; MyRedisDB.SetAdd(key, msg); } } else { user.Name = githubUser.name; user.AvatarUrl = githubUser.avatar_url; user.GitHubID = githubUser.id; user.GitHubLogin = githubUser.login; user.GitHubAccessToken = token; user.Email = githubUser.email; user.FollowingCount = githubUser.following; user.FollowerCount = githubUser.followers; NullUserDataSvc.Update(user); } HttpContext.WriteCookie("UID", user.ID.ToString(), DateTime.Now.AddYears(3)); HttpContext.WriteCookie("UName", HttpUtility.UrlEncode(githubUser.name), DateTime.Now.AddYears(3)); HttpContext.WriteCookie("UAvatar", githubUser.avatar_url, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("LoginType", user.LoginType, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("GLogin", githubUser.login, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("SKEY", Utils.RijndaelEncrypt(user.ID.ToString()), DateTime.Now.AddYears(3)); HttpContext.WriteCookie("Role", Utils.RijndaelEncrypt(user.ID.ToString() + ";" + user.Role.ToString()), DateTime.Now.AddYears(3)); } return(true); }
//添加用户或更新用户信息 public bool UpdateUserInfo(string loginType, string token) { if (loginType == "github") { GitHubUser githubUser = GitHub.GetGitHubUser(token); if (githubUser.id == 0) { return(false); } NullUser user = NullUserDataSvc.GetByCondition(u => u.GitHubID == githubUser.id).FirstOrDefault(); if (user == null) { user = new NullUser(); user.LoginType = "github"; user.GitHubAccessToken = token; user.Name = githubUser.name; user.AvatarUrl = githubUser.avatar_url; user.GitHubLogin = githubUser.login; user.GitHubID = githubUser.id; user.Role = (int)EnumUserRole.普通; user.Email = githubUser.email; NullUserDataSvc.Add(user); if (string.IsNullOrEmpty(user.Email)) { SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "您还未设置邮箱"; msg.Msg = "请到<a href=\"/Home/UserProfile\">我的主页</a>设置或修改<a href=\"https://github.com/settings/profile\" target=\"_blank\">GitHub</a>邮箱显示后更新账号。"; string key = MyRedisKeys.Pre_SysMsg + user.ID; MyRedisDB.SetAdd(key, msg); } //添加一篇newbee //NewBee nb = new NewBee(); //nb.OwnerID = user.ID; //nb.Title = "大家好,我是" + (string.IsNullOrEmpty(user.Name) ? user.GitHubLogin : user.Name) + ",很高兴加入象空。"; //nb.FloorCount = 1; //nb.LastFloorDate = DateTime.Now; //NewBeeDataSvc.Add(nb); //NewBeeFloor nbf = new NewBeeFloor(); //nbf.MDText = "我刚刚加入象空,点击查看更多关于我的信息,如果你有兴趣可以关注我的GitHub。"; //nbf.MDValue = "<p>我刚刚加入象空,点击查看更多关于我的信息,如果你有兴趣可以关注我的GitHub。</p>"; //nbf.NewBeeID = nb.ID; //nbf.Order = 1; //nbf.OwnerID = user.ID; //NewBeeFloorDataSvc.Add(nbf); } else { user.Name = githubUser.name; user.AvatarUrl = githubUser.avatar_url; user.GitHubID = githubUser.id; user.GitHubLogin = githubUser.login; user.GitHubAccessToken = token; user.Email = githubUser.email; NullUserDataSvc.Update(user); } HttpContext.WriteCookie("UID", user.ID.ToString(), DateTime.Now.AddYears(3)); HttpContext.WriteCookie("UName", githubUser.name, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("UAvatar", githubUser.avatar_url, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("LoginType", user.LoginType, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("GLogin", githubUser.login, DateTime.Now.AddYears(3)); HttpContext.WriteCookie("SKEY", Utils.RijndaelEncrypt(user.ID.ToString()), DateTime.Now.AddYears(3)); HttpContext.WriteCookie("Role", Utils.RijndaelEncrypt(user.ID.ToString() + ";" + user.Role.ToString()), DateTime.Now.AddYears(3)); } return(true); }
public static void InitDic() { DataSet ds = new DataSet(); DataTable dt = null; Dictionary dic; SysConfig config; SysMsg sysmsg; string sqlData = @"select 'fin_inst' dic_type, cast([inst_code] as nvarchar) id, inst_name name, inst_name2 name2, inst_param1 extra, inst_param2 extra2 from [dic_fin_inst] SELECT * FROM sys_msg order by msg_no, msg_lang; SELECT * FROM sys_config ORDER BY config_key;"; Result res = DataSetExecute(sqlData, 1); try { if (res.Succeed) { if (App.dicTable != null && App.dicTable.Count > 0) { App.dicTable.Clear(); } ds = (DataSet)res.Data; dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { dic = new Dictionary { dicType = Func.ToStr(row["dic_Type"]), id = Func.ToStr(row["id"]), name = Func.ToStr(row["name"]), name2 = Func.ToStr(row["name2"]), extra = Func.ToStr(row["extra"]), extra2 = Func.ToStr(row["extra2"]) }; if (dic.dicType == "address") { dicAddress.Add(dic.id, dic); } else if (dic.dicType == "product_item") { dicTable.Add(dic.dicType + "*" + dic.id + "~" + dic.extra2, dic); } else { dicTable.Add(dic.dicType + "*" + dic.id, dic); } } App.sysMsg = new System.Collections.Hashtable(); dt = ds.Tables[1]; foreach (DataRow row in dt.Rows) { sysmsg = new SysMsg { msg_no = Func.ToInt(row["msg_no"]), msg_text = Func.ToStr(row["msg_text"]), lang = Func.ToInt(row["msg_lang"]) }; sysMsg.Add(Func.ToStr(sysmsg.msg_no) + keydelm + Func.ToStr(sysmsg.lang), sysmsg.msg_text); } App.sysConfig = new System.Collections.Hashtable(); dt = ds.Tables[2]; foreach (DataRow row in dt.Rows) { config = new SysConfig { config_key = Func.ToStr(row["config_Key"]), config_value = Func.ToStr(row["config_Value"]), config_type = Func.ToStr(row["config_type"]), config_value2 = Func.ToStr(row["config_value2"]) }; sysConfig.Add(config.config_key, config); } dt.Dispose(); dt = null; ds.Dispose(); ds = null; dic = null; config = null; sysmsg = null; } else { Main.ErrorLog("AppConfig-DicInit", res.Desc); } } catch (Exception ex) { Main.ErrorLog("AppConfig-DicInit", ex); } }
public void HandlingMsg() { while (this.flag) { try{ //接收服务器消息 var protocolChat = this.Receive(); switch (protocolChat.model) { case 1: //用户 switch (protocolChat.ope) { case 1: // 注册 break; case 2: // 登录 SysMsg sysmsg = protocolChat.data as SysMsg; this.DataWriteLine(sysmsg.Type, "登录返回消息"); break; case 3: // 找回密码 break; default: break; } break; case 2: //聊天 switch (protocolChat.ope) { case 0: //在线用户列表 userList = protocolChat.data as List <UserData>; this.DataWriteLine(0, "更新列表"); break; case 1: // 聊天消息 ChatMsg chatMsg = protocolChat.data as ChatMsg; if (chatMsg.ReceiveName != myName) { this.DataWriteLine(1, "【" + chatMsg.SendName + "】说:" + chatMsg.Content); } else { this.DataWriteLine(2, "【" + chatMsg.SendName + "】悄悄对你说:" + chatMsg.Content); } break; case 2: //用户上线 var user1 = protocolChat.data as UserData; userList.Add(user1); this.DataWriteLine(0, "更新列表"); this.DataWriteLine(3, "系统消息:用户【" + user1.Id + "】上线了"); break; case 3: //用户下线 var user2 = protocolChat.data as UserData; for (int i = 0; i < userList.Count; i++) { if (userList[i].Id == user2.Id) { userList.Remove(userList[i]); break; } } this.DataWriteLine(3, "系统消息:用户【" + user2.Id + "】下线了"); this.DataWriteLine(0, "更新列表"); break; default: break; } break; case 3: break; default: break; } } //和服务器断开了 catch { //这里当服务器关闭或网络中断时会出现异常 this.DataWriteLine(4, "和服务器断开了"); this.flag = false; break; } } //退出监听服务器消息 }
public void HandlingMsg(object obj) { Socket client = obj as Socket; while (this.flag) { try{ //接收客户端消息 var protocolChat = Receive(client); switch (protocolChat.model) { case 1: //用户 switch (protocolChat.ope) { case 1: //注册 var userInfo1 = protocolChat.data as UserInfo; //得到用户数据 break; case 2: //登录 var userInfo2 = protocolChat.data as UserInfo; //如果userInfo2.Name key键不存在 if (!clientDic.ContainsKey(userInfo2.Name)) { //用户登录成功! DataWriteLine(0, "[" + userInfo2.Name + "]用户上线了……"); ClientData clientdata = new ClientData(); clientdata.Client = client; clientdata.id = userInfo2.Name; clientdata.name = userInfo2.Name; //当前客户端用户信息添加进在线用户字典 clientDic.Add(userInfo2.Name, clientdata); SysMsg sysmsg = new SysMsg(); sysmsg.Type = 0; protocolChat.data = sysmsg; //向客户端发送登录成功消息 Send(client, protocolChat); //广播通知所有客户端有用户上线 protocolChat.model = 2; //聊天 protocolChat.ope = 2; //上线 UserData user = new UserData(); user.Id = userInfo2.Name; user.Name = userInfo2.Name; protocolChat.data = user; Broadcast(client, protocolChat); } else { SysMsg sysmsg = new SysMsg(); sysmsg.Type = 1; protocolChat.data = sysmsg; //向客户端发送登录失败消息 Send(client, protocolChat); return; } break; case 3: //找回密码 break; default: break; } break; case 2: //聊天 switch (protocolChat.ope) { case 0: //在线用户列表(客户端请求在线用户列表) List <UserData> userList = new List <UserData>(); foreach (KeyValuePair <string, ClientData> kvp in clientDic) { UserData tempUserData = new UserData(); tempUserData.Id = kvp.Value.id; tempUserData.Name = kvp.Value.name; userList.Add(tempUserData); } protocolChat.data = userList; Send(client, protocolChat); break; case 1: //聊天消息 var charMsg = protocolChat.data as ChatMsg; //得到用户数据 if (charMsg.ReceiveName == "所有人") { DataWriteLine(0, "用户[" + charMsg.SendName + "]说:" + charMsg.Content); //向所有客户端广播消息 Broadcast(client, protocolChat); } else { try{ //如果charMsg.ReceiveName key键存在 if (clientDic.ContainsKey(charMsg.ReceiveName)) { //向指定的人发送消息 DataWriteLine(0, "用户[" + charMsg.SendName + "]悄悄地对[" + charMsg.ReceiveName + "]说:" + charMsg.Content); Send(clientDic[charMsg.ReceiveName].Client, protocolChat); } } catch {} } break; case 2: break; default: break; } break; case 3: break; default: break; } } catch { //如果出错和客户端断开 在线用户列表移除用户数据 foreach (KeyValuePair <string, ClientData> kvp in clientDic) { if (kvp.Value.Client == client) { //广播通知所有客户端有用户下线 ProtocolChat chat = new ProtocolChat(); chat.model = 2; //聊天 chat.ope = 3; //下线 UserData user = new UserData(); user.Id = kvp.Value.id; user.Name = kvp.Value.name; chat.data = user; Broadcast(client, chat); //客户端列表删除断开的用户 clientDic.Remove(kvp.Key); DataWriteLine(0, "用户[" + kvp.Value.name + "]下线了"); break; } } } } }
/// <summary> /// 响应Response /// </summary> private static SysMsg GetApiResponse(string message) { return(SysMsg.Fail(message)); }