public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } if (!commandParam.CheckRequiredParams("password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string password = commandParam.GetDNTParam("password").ToString(); bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString() == "md5" ? true : false; EncodePasswordResponse epr = new EncodePasswordResponse(); epr.Password = Utils.UrlEncode(ForumUtils.SetCookiePassword(isMD5Passwd ? password : Utils.MD5(password), commandParam.GeneralConfig.Passwordkey)); result = commandParam.Format == FormatType.JSON ? string.Format("\"{0}\"", epr.Password) : SerializationHelper.Serialize(epr); return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } if (!commandParam.CheckRequiredParams("user_name")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } int uid = Users.GetUserId(commandParam.GetDNTParam("user_name").ToString()); if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", uid); } else { GetIDResponse gir = new GetIDResponse(); gir.UId = uid; result = SerializationHelper.Serialize(gir); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("uid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } int uid = commandParam.GetIntParam("uid"); int pageSize = commandParam.GetIntParam("page_size", 10); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? 10 : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; List <PrivateMessageInfo> list = PrivateMessages.GetPrivateMessageCollection(uid, 0, pageSize, pageIndex, 1); List <Message> newList = new List <Message>(); foreach (PrivateMessageInfo pm in list) { Message m = new Message(); m.MessageId = pm.Pmid; m.From = pm.Msgfrom; m.FromId = pm.Msgfromid; m.MessageContent = pm.Message; m.PostDateTime = pm.Postdatetime; m.Subject = pm.Subject; newList.Add(m); } MessageGetResponse mgr = new MessageGetResponse(); mgr.Count = PrivateMessages.GetPrivateMessageCount(uid, 0, 1); mgr.List = true; mgr.Messages = newList.ToArray(); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(mgr) : Util.AddMessageCDATA(SerializationHelper.Serialize(mgr)); return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } //如果当前用户不是管理员 if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } // recipients subject if (!commandParam.CheckRequiredParams("recipients,subject,text")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string recipients = commandParam.GetDNTParam("recipients").ToString(); if (!Utils.IsNumericList(recipients)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } //需要过滤部分html标签,待开发 //得到了 用逗号分隔的ids 和 subject,先通过ids得到所有人的用户名 string uids = Discuz.Forum.Emails.SendMailToUsers(recipients, commandParam.GetDNTParam("subject").ToString(), commandParam.GetDNTParam("text").ToString()); if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", uids); } else { NotificationSendEmailResponse nser = new NotificationSendEmailResponse(); nser.Recipients = uids; result = SerializationHelper.Serialize(nser); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } ShortUserInfo userInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (userInfo == null || userInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("forum_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } Forum forum; try { forum = JavaScriptConvert.DeserializeObject <Forum>(commandParam.GetDNTParam("forum_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (forum == null || string.IsNullOrEmpty(forum.Name)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (!Utils.StrIsNullOrEmpty(forum.RewriteName) && Discuz.Forum.Forums.CheckRewriteNameInvalid(forum.RewriteName)) { result = Util.CreateErrorMessage(ErrorType.API_EC_REWRITENAME, commandParam.ParamList); return(false); } int fid; if (forum.ParentId > 0) { #region 添加与当前论坛同级的论坛 //添加与当前论坛同级的论坛 ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(forum.ParentId); //找出当前要插入的记录所用的FID string parentidlist = null; parentidlist = forumInfo.Parentidlist == "0" ? forumInfo.Fid.ToString() : forumInfo.Parentidlist + "," + forumInfo.Fid; DataTable dt = AdminForums.GetMaxDisplayOrder(forum.ParentId); int maxdisplayorder = (dt.Rows.Count > 0) && (dt.Rows[0][0].ToString() != "") ? Convert.ToInt32(dt.Rows[0][0]) : forumInfo.Displayorder; AdminForums.UpdateForumsDisplayOrder(maxdisplayorder); fid = ForumsCommandUtils.InsertForum(forum, forumInfo.Layer + 1, parentidlist, 0, maxdisplayorder + 1); AdminForums.SetSubForumCount(forumInfo.Fid); #endregion } else { #region 根论坛插入 int maxdisplayorder = AdminForums.GetMaxDisplayOrder(); fid = ForumsCommandUtils.InsertForum(forum, 0, "0", 0, maxdisplayorder); #endregion } ForumCreateResponse fcr = new ForumCreateResponse(); fcr.Fid = fid; fcr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Urls.ShowForumAspxRewrite(fid, 1, forum.RewriteName); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(fcr) : SerializationHelper.Serialize(fcr); return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { int uid = commandParam.GetIntParam("uid"); //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (commandParam.LocalUid != uid) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("uid,original_password,new_password,confirm_new_password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string originalPassword = commandParam.GetDNTParam("original_password").ToString(); string newPassword = commandParam.GetDNTParam("new_password").ToString(); string confirmNewPassword = commandParam.GetDNTParam("confirm_new_password").ToString(); if (newPassword != confirmNewPassword) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString().ToLower() == "md5"; ShortUserInfo user = Discuz.Forum.Users.GetShortUserInfo(uid); if (!isMD5Passwd) originalPassword = Utils.MD5(originalPassword); if (user.Password != originalPassword) { result = Util.CreateErrorMessage(ErrorType.API_EC_ORI_PASSWORD_EQUAL_FALSE, commandParam.ParamList); return false; } bool updateSuccess = Discuz.Forum.Users.UpdateUserPassword(uid, newPassword, !isMD5Passwd); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", updateSuccess.ToString().ToLower()); else { ChangePasswordResponse cpr = new ChangePasswordResponse(); cpr.Successfull = updateSuccess ? 1 : 0; result = SerializationHelper.Serialize(cpr); } return true; }
/* * Description: * 该接口需要能关联到一个论坛用户,不允许游客操作,如果validate=true或者接口类型为桌面程序,则只获取session_info中的uid,若无则返回API_EC_SESSIONKEY */ public override bool Run(CommandParameter commandParam, ref string result) { //如果validate为true,则校验数据的合法性,包括广告强力屏蔽,是否含有需审核的,以及非法内容.和当前用户的发帖权限 bool validate = commandParam.GetIntParam("validate") == 1 || commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP; //如果validate是true或者桌面程序则需要验证用户身份 if (validate && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("topic_info,tid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } Topic topic; try { topic = JavaScriptConvert.DeserializeObject<Topic>(commandParam.GetDNTParam("topic_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (topic == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } //文档中应说明title长度范围和内容范围 if (!Util.AreParamsNullOrZeroOrEmptyString(topic.Title) && topic.Title.Length > 60) { result = Util.CreateErrorMessage(ErrorType.API_EC_TITLE_INVALID, commandParam.ParamList); return false; } //编辑主题必须要能关联到一个用户 ShortUserInfo userInfo = Users.GetShortUserInfo(validate || topic.UId == null ? commandParam.LocalUid : (int)topic.UId); if (userInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_NOUSER, commandParam.ParamList); return false; } TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(commandParam.GetIntParam("tid", 0)); if (topicInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topic.Fid ?? topicInfo.Fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } UserGroupInfo userGroupInfo = UserGroups.GetUserGroupInfo(userInfo.Groupid); AdminGroupInfo adminInfo = AdminGroups.GetAdminGroupInfo(userGroupInfo.Groupid); //是否受审核、过滤、灌水等限制权限 int disablePost = adminInfo != null ? adminInfo.Disablepostctrl : userGroupInfo.Disableperiodctrl; bool hasAudit = false; if (validate) { string title = topic.Title ?? ""; string message = topic.Message ?? ""; ErrorType et = TopicsCommandUtils.GeneralValidate(title, message, userInfo, userGroupInfo, forumInfo, commandParam, disablePost); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //如果主题作者与当前用户不一样且当前用户不是管理员 if (topicInfo.Posterid != commandParam.LocalUid && userInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList); return false; } //如果当前用户是管理组成员,则跳过编辑时间限制校验 if (!Moderators.IsModer(userInfo.Adminid, commandParam.LocalUid, forumInfo.Fid)) { if (commandParam.GeneralConfig.Edittimelimit == -1) { result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList); return false; } if (commandParam.GeneralConfig.Edittimelimit > 0 && Utils.StrDateDiffSeconds(topicInfo.Postdatetime, commandParam.GeneralConfig.Edittimelimit) > 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList); return false; } } if (!string.IsNullOrEmpty(title + message)) { if (ForumUtils.HasAuditWord(title) || ForumUtils.HasAuditWord(message)) hasAudit = true; if (disablePost != 1) { topic.Title = ForumUtils.BanWordFilter(topic.Title); topic.Message = ForumUtils.BanWordFilter(topic.Message); } } } topic.Iconid = topic.Iconid ?? 0; topic.Iconid = topic.Iconid > 15 || topic.Iconid < 0 ? 0 : topic.Iconid; topicInfo.Fid = topic.Fid ?? topicInfo.Fid; topicInfo.Iconid = (int)topic.Iconid; topicInfo.Title = topic.Title != null ? Utils.HtmlEncode(topic.Title) : topicInfo.Title; topicInfo.Displayorder = hasAudit ? -2 : topicInfo.Displayorder; if (topic.Message != null) { bool htmlon = topic.Message.Length != Utils.RemoveHtml(topic.Message).Length && userGroupInfo.Allowhtml == 1; topic.Message = htmlon ? Utils.HtmlDecode(topic.Message) : topic.Message; } bool enabletag = (commandParam.GeneralConfig.Enabletag & forumInfo.Allowtag) == 1; string tags = string.Empty; string[] tagArray = null; if (!string.IsNullOrEmpty(topic.Tags)) { //标签(Tag)操作 tags = topic.Tags.Trim(); tagArray = Utils.SplitString(tags, ",", true, 2, 10); if (enabletag) { if (topicInfo.Magic == 0) topicInfo.Magic = 10000; topicInfo.Magic = Utils.StrToInt(topicInfo.Magic.ToString() + "1", 0); } } if (forumInfo.Applytopictype == 1) { if (Discuz.Forum.Forums.IsCurrentForumTopicType(topic.Typeid.ToString(), forumInfo.Topictypes)) { topicInfo.Typeid = (int)topic.Typeid; } else if (forumInfo.Postbytopictype == 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } } int editResult = Discuz.Forum.Topics.UpdateTopic(topicInfo); if (enabletag && tagArray != null && tagArray.Length > 0) { if (disablePost == 1 || !ForumUtils.HasBannedWord(tags)) ForumTags.CreateTopicTags(tagArray, topicInfo.Tid, userInfo.Uid, topicInfo.Postdatetime); } PostInfo postInfo = Discuz.Forum.Posts.GetPostInfo(topicInfo.Tid, Discuz.Forum.Posts.GetFirstPostId(topicInfo.Tid)); if (topic.Fid != null) postInfo.Fid = forumInfo.Fid; if (topic.Title != null) { postInfo.Title = topicInfo.Title; postInfo.Topictitle = topicInfo.Title; } postInfo.Message = topic.Message ?? postInfo.Message; editResult = Posts.UpdatePost(postInfo); TopicEditResponse ter = new TopicEditResponse(); ter.Successfull = editResult; result = commandParam.Format == FormatType.JSON ? (editResult == 1).ToString().ToLower() : SerializationHelper.Serialize(ter); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.WEB) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } if (commandParam.LocalUid > 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ONLINE, commandParam.ParamList); return(false); } if (!commandParam.CheckRequiredParams("user_name,password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5) { result = Util.CreateErrorMessage(ErrorType.API_EC_MORE_LOGIN_FAILED, commandParam.ParamList); return(false); } string loginName = commandParam.GetDNTParam("user_name").ToString(); string password = commandParam.GetDNTParam("password").ToString(); string passwordFormat = commandParam.CheckRequiredParams("password_format") ? commandParam.GetDNTParam("password_format").ToString() : ""; int expires = commandParam.GetIntParam("expires"); expires = expires > 0 ? expires : 999; int userId = -1; ShortUserInfo userInfo = new ShortUserInfo(); if (commandParam.GeneralConfig.Emaillogin == 1 && Utils.IsValidEmail(loginName)) { DataTable dt = Users.GetUserInfoByEmail(loginName); if (dt.Rows.Count == 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return(false); } if (dt.Rows.Count > 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SAME_USER_EMAIL, commandParam.ParamList); return(false); } loginName = dt.Rows[0]["username"].ToString(); userId = TypeConverter.ObjectToInt(dt.Rows[0]["uid"]); userInfo.Uid = userId; userInfo.Username = loginName; userInfo.Groupid = TypeConverter.ObjectToInt(dt.Rows[0]["groupid"]); userInfo.Groupexpiry = TypeConverter.ObjectToInt(dt.Rows[0]["groupexpiry"]); userInfo.Credits = TypeConverter.ObjectToInt(dt.Rows[0]["credits"]); userInfo.Email = dt.Rows[0]["email"].ToString(); userInfo.Password = dt.Rows[0]["password"].ToString(); } else { userId = Users.GetUserId(loginName); if (userId < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return(false); } userInfo = Users.GetShortUserInfo(userId); } int uid = -1; if (passwordFormat == "") { switch (commandParam.GeneralConfig.Passwordmode) { case 0: //默认模式 { uid = Users.CheckPassword(loginName, password, true); break; } case 1: //动网兼容模式 { uid = Users.CheckDvBbsPassword(loginName, password); break; } } } else { uid = userInfo.Password == password ? userInfo.Uid : -1; } if (uid != userInfo.Uid) { LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true); result = Util.CreateErrorMessage(ErrorType.API_EC_WRONG_PASSWORD, commandParam.ParamList); return(false); } #region 当前用户所在用户组为"禁止访问"或"等待激活"时 if ((userInfo.Groupid == 4 || userInfo.Groupid == 5) && userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) { //根据当前用户的积分获取对应积分用户组 UserGroupInfo groupInfo = CreditsFacade.GetCreditsUserGroupId(userInfo.Credits); Users.UpdateUserGroup(userInfo.Uid, userInfo.Groupid); } #endregion if (userInfo.Groupid == 5 || userInfo.Groupid == 8)// 5-禁止访问或者需要激活帐号的用户 { result = Util.CreateErrorMessage(ErrorType.API_EC_BANNED_USERGROUP, commandParam.ParamList); return(false); } #region 无延迟更新在线信息和相关用户信息 ForumUtils.WriteUserCookie(userInfo.Uid, expires, commandParam.GeneralConfig.Passwordkey, 0, -1); OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(commandParam.GeneralConfig.Passwordkey, commandParam.GeneralConfig.Onlinetimeout, userInfo.Uid, ""); OnlineUsers.UpdateAction(oluserinfo.Olid, UserAction.Login.ActionID, 0); LoginLogs.DeleteLoginLog(DNTRequest.GetIP()); Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP()); #endregion result = "success"; result = commandParam.Format == FormatType.JSON ? string.Format("\"{0}\"", result) : SerializationHelper.Serialize(result); return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("fid,tid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = commandParam.GetIntParam("fid"); ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } int tid = commandParam.GetIntParam("tid"); TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid); if (topicInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList); return false; } int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Ppp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Ppp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; PostpramsInfo postPramsInfo = TopicsCommandUtils.GetPostParamInfo(commandParam.LocalUid, topicInfo, forumInfo, pageSize, pageIndex); System.Data.DataTable lastpostlist = Posts.GetPagedLastDataTable(postPramsInfo); List<Post> list = new List<Post>(); foreach (System.Data.DataRow dr in lastpostlist.Rows) { Post post = new Post(); post.AdIndex = Utils.StrToInt(dr["adindex"], 0); post.Invisible = Utils.StrToInt(dr["invisible"], 0); post.Layer = Utils.StrToInt(dr["layer"], 0); post.Message = dr["message"].ToString(); post.Pid = Utils.StrToInt(dr["pid"], 0); post.PostDateTime = DateTime.Parse(dr["postdatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); post.PosterAvator = dr["avatar"].ToString().Replace("\\", "/"); post.PosterAvatorWidth = Utils.StrToInt(dr["avatarwidth"], 0); post.PosterAvatorHeight = Utils.StrToInt(dr["avatarheight"], 0); post.PosterEmail = dr["email"].ToString().Trim(); post.PosterId = Utils.StrToInt(dr["posterid"], 0); post.PosterLocation = dr["location"].ToString(); post.PosterName = dr["poster"].ToString(); post.PosterShowEmail = Utils.StrToInt(dr["showemail"], 0); post.PosterSignature = dr["signature"].ToString(); post.Rate = Utils.StrToInt(dr["rate"], 0); post.RateTimes = Utils.StrToInt(dr["ratetimes"], 0); post.UseSignature = Utils.StrToInt(dr["usesig"], 0); list.Add(post); } TopicGetRencentRepliesResponse tgrrr = new TopicGetRencentRepliesResponse(); tgrrr.List = true; tgrrr.Count = topicInfo.Replies; tgrrr.Posts = list.ToArray(); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tgrrr) : Util.AddMessageCDATA(SerializationHelper.Serialize(tgrrr)); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("fid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = commandParam.GetIntParam("fid", 0); int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Tpp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Tpp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; int count = Discuz.Forum.Topics.GetAttentionTopicCount(fid.ToString(), string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetAttentionTopics(fid.ToString(), pageSize, pageIndex, string.Empty); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tglr) : SerializationHelper.Serialize(tglr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } if (!commandParam.CheckRequiredParams("user_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } UserForEditing ufe; try { ufe = JavaScriptConvert.DeserializeObject <UserForEditing>(commandParam.GetDNTParam("user_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } #region 用户信息读取及权限校验 int uid = commandParam.GetIntParam("uid"); uid = uid > 0 ? uid : commandParam.LocalUid; if (uid <= 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } UserInfo localUserInfo = null; //终端应用程序需要校验当前用户权限,不是管理员则只能修改自己的资料 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { localUserInfo = Users.GetUserInfo(commandParam.LocalUid); if (localUserInfo == null || (localUserInfo.Uid != uid && localUserInfo.Adminid != 1)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } UserInfo userInfo = localUserInfo != null && localUserInfo.Uid == uid ? localUserInfo : Users.GetUserInfo(uid); if (userInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return(false); } #endregion if (!string.IsNullOrEmpty(ufe.Email)) { if (!UserCommandUtils.CheckEmail(ufe.Email, commandParam.GeneralConfig.Accessemail)) { result = Util.CreateErrorMessage(ErrorType.API_EC_EMAIL, commandParam.ParamList); return(false); } userInfo.Email = ufe.Email; } if (!string.IsNullOrEmpty(ufe.Password)) { userInfo.Password = ufe.Password; } if (!string.IsNullOrEmpty(ufe.Bio)) { userInfo.Bio = ufe.Bio; } if (!string.IsNullOrEmpty(ufe.Birthday)) { userInfo.Bday = ufe.Birthday; } if (!string.IsNullOrEmpty(ufe.ExtCredits1)) { userInfo.Extcredits1 = Utils.StrToFloat(ufe.ExtCredits1, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits2)) { userInfo.Extcredits2 = Utils.StrToFloat(ufe.ExtCredits2, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits3)) { userInfo.Extcredits3 = Utils.StrToFloat(ufe.ExtCredits3, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits4)) { userInfo.Extcredits4 = Utils.StrToFloat(ufe.ExtCredits4, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits5)) { userInfo.Extcredits5 = Utils.StrToFloat(ufe.ExtCredits5, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits6)) { userInfo.Extcredits6 = Utils.StrToFloat(ufe.ExtCredits6, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits7)) { userInfo.Extcredits7 = Utils.StrToFloat(ufe.ExtCredits7, 0); } if (!string.IsNullOrEmpty(ufe.ExtCredits8)) { userInfo.Extcredits8 = Utils.StrToFloat(ufe.ExtCredits8, 0); } if (!string.IsNullOrEmpty(ufe.Gender)) { userInfo.Gender = Utils.StrToInt(ufe.Gender, 0); } if (!string.IsNullOrEmpty(ufe.Icq)) { userInfo.Icq = ufe.Icq; } if (!string.IsNullOrEmpty(ufe.IdCard)) { userInfo.Idcard = ufe.IdCard; } if (!string.IsNullOrEmpty(ufe.Location)) { userInfo.Location = ufe.Location; } if (!string.IsNullOrEmpty(ufe.Mobile)) { userInfo.Mobile = ufe.Mobile; } if (!string.IsNullOrEmpty(ufe.Msn)) { userInfo.Msn = ufe.Msn; } if (!string.IsNullOrEmpty(ufe.NickName)) { userInfo.Nickname = ufe.NickName; } if (!string.IsNullOrEmpty(ufe.Phone)) { userInfo.Phone = ufe.Phone; } if (!string.IsNullOrEmpty(ufe.Qq)) { userInfo.Qq = ufe.Qq; } if (!string.IsNullOrEmpty(ufe.RealName)) { userInfo.Realname = ufe.RealName; } if (!string.IsNullOrEmpty(ufe.Skype)) { userInfo.Skype = ufe.Skype; } if (!string.IsNullOrEmpty(ufe.SpaceId)) { userInfo.Spaceid = Utils.StrToInt(ufe.SpaceId, 0); } if (!string.IsNullOrEmpty(ufe.WebSite)) { userInfo.Website = ufe.WebSite; } if (!string.IsNullOrEmpty(ufe.Yahoo)) { userInfo.Yahoo = ufe.Yahoo; } try { Users.UpdateUser(userInfo); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_UNKNOWN, commandParam.ParamList); return(false); } if (commandParam.Format == FormatType.JSON) { result = "true"; } else { SetInfoResponse sir = new SetInfoResponse(); sir.Successfull = 1; result = SerializationHelper.Serialize(sir); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { ShortUserInfo localUserInfo = null; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } localUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (localUserInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("uids,fields")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string[] uIds = commandParam.GetDNTParam("uids").ToString().Split(','); //单次最多接受查询100个用户 if (!Utils.IsNumericArray(uIds) || Utils.StrToInt(uIds[0], -1) < 1 || uIds.Length > 100) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } List <User> userList = new List <User>(); UserInfo userInfo; for (int i = 0; i < uIds.Length; i++) { int userid = Utils.StrToInt(uIds[i], -1); if (userid < 1) { continue; } userInfo = Discuz.Forum.Users.GetUserInfo(userid); if (userInfo == null) { continue; } bool loadAuthAttr = true; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { loadAuthAttr = userInfo.Uid == localUserInfo.Uid || localUserInfo.Adminid == 1; } userList.Add(UserCommandUtils.LoadSingleUser(userInfo, commandParam.GetDNTParam("fields").ToString(), loadAuthAttr)); } UserInfoResponse uir = new UserInfoResponse(); uir.user_array = userList.ToArray(); uir.List = true; if (commandParam.Format == FormatType.JSON) { result = Util.RemoveJsonNull(JavaScriptConvert.SerializeObject(userList.ToArray())); } else { //如果userList长度不大于1,则移除空节点会导致客户端反序列化错误 //result = userList.Count > 1 ? Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()) : //SerializationHelper.Serialize(uir); result = Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } //如果当前用户不是管理员 if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } // recipients subject if (!commandParam.CheckRequiredParams("recipients,subject,text")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string recipients = commandParam.GetDNTParam("recipients").ToString(); if (!Utils.IsNumericList(recipients)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } //需要过滤部分html标签,待开发 //得到了 用逗号分隔的ids 和 subject,先通过ids得到所有人的用户名 string uids = Discuz.Forum.Emails.SendMailToUsers(recipients, commandParam.GetDNTParam("subject").ToString(), commandParam.GetDNTParam("text").ToString()); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", uids); else { NotificationSendEmailResponse nser = new NotificationSendEmailResponse(); nser.Recipients = uids; result = SerializationHelper.Serialize(nser); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } //如果当前用户不是管理员 if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("notification")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } //给当前登录用户发送通知可以将to_ids设置为空 if (commandParam.LocalUid < 1 && (!commandParam.CheckRequiredParams("to_ids") || !Utils.IsNumericList(commandParam.GetDNTParam("to_ids").ToString()))) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string ids = commandParam.GetDNTParam("to_ids").ToString(); string notification = commandParam.GetDNTParam("notification").ToString(); string[] to_ids; if (ids == string.Empty) { to_ids = new string[1]; to_ids[0] = commandParam.LocalUid.ToString(); } else { to_ids = commandParam.GetDNTParam("to_ids").ToString().Split(','); } string successfulIds = string.Empty; ShortUserInfo shortUserInfo = null; if (commandParam.LocalUid > 0) shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid); foreach (string id in to_ids) { if (Utils.StrToInt(id, 0) < 1) continue; NoticeInfo noticeinfo = new NoticeInfo(); noticeinfo.Uid = Utils.StrToInt(id, 0); noticeinfo.New = 1; noticeinfo.Postdatetime = Utils.GetDateTime(); //如果应用程序没有指定来源id,则会将当前应用程序id的hash值作为来源ID,若不指定来源id,用户的通知列表中只存在一条最新的应用程序通知 noticeinfo.Fromid = commandParam.GetIntParam("from_id", Utils.BKDEHash(commandParam.AppInfo.APIKey, 113)); //如果应用程序指定了来源id,则通知类型为“应用程序自定义通知”,否则是“应用程序通知” noticeinfo.Type = commandParam.CheckRequiredParams("from_id") ? NoticeType.ApplicationCustomNotice : NoticeType.ApplicationNotice; if (commandParam.LocalUid > 0) { noticeinfo.Poster = shortUserInfo == null ? "" : shortUserInfo.Username; noticeinfo.Posterid = commandParam.LocalUid; } else { noticeinfo.Poster = ""; noticeinfo.Posterid = 0; } noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换 if (Notices.CreateNoticeInfo(noticeinfo) > 0) successfulIds += (id + ","); } if (successfulIds.Length > 0) successfulIds = successfulIds.Remove(successfulIds.Length - 1); if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", successfulIds); } else { NotificationSendResponse nsr = new NotificationSendResponse(); nsr.Result = successfulIds; result = SerializationHelper.Serialize(nsr); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.WEB) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } if (commandParam.LocalUid > 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ONLINE, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("user_name,password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5) { result = Util.CreateErrorMessage(ErrorType.API_EC_MORE_LOGIN_FAILED, commandParam.ParamList); return false; } string loginName = commandParam.GetDNTParam("user_name").ToString(); string password = commandParam.GetDNTParam("password").ToString(); string passwordFormat = commandParam.CheckRequiredParams("password_format") ? commandParam.GetDNTParam("password_format").ToString() : ""; int expires = commandParam.GetIntParam("expires"); expires = expires > 0 ? expires : 999; int userId = -1; ShortUserInfo userInfo = new ShortUserInfo(); if (commandParam.GeneralConfig.Emaillogin == 1 && Utils.IsValidEmail(loginName)) { DataTable dt = Users.GetUserInfoByEmail(loginName); if (dt.Rows.Count == 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return false; } if (dt.Rows.Count > 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SAME_USER_EMAIL, commandParam.ParamList); return false; } loginName = dt.Rows[0]["username"].ToString(); userId = TypeConverter.ObjectToInt(dt.Rows[0]["uid"]); userInfo.Uid = userId; userInfo.Username = loginName; userInfo.Groupid = TypeConverter.ObjectToInt(dt.Rows[0]["groupid"]); userInfo.Groupexpiry = TypeConverter.ObjectToInt(dt.Rows[0]["groupexpiry"]); userInfo.Credits = TypeConverter.ObjectToInt(dt.Rows[0]["credits"]); userInfo.Email = dt.Rows[0]["email"].ToString(); userInfo.Password = dt.Rows[0]["password"].ToString(); } else { userId = Users.GetUserId(loginName); if (userId < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return false; } userInfo = Users.GetShortUserInfo(userId); } int uid = -1; if (passwordFormat == "") { switch (commandParam.GeneralConfig.Passwordmode) { case 0://默认模式 { uid = Users.CheckPassword(loginName, password, true); break; } case 1://动网兼容模式 { uid = Users.CheckDvBbsPassword(loginName, password); break; } } } else { uid = userInfo.Password == password ? userInfo.Uid : -1; } if (uid != userInfo.Uid) { LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true); result = Util.CreateErrorMessage(ErrorType.API_EC_WRONG_PASSWORD, commandParam.ParamList); return false; } #region 当前用户所在用户组为"禁止访问"或"等待激活"时 if ((userInfo.Groupid == 4 || userInfo.Groupid == 5) && userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) { //根据当前用户的积分获取对应积分用户组 UserGroupInfo groupInfo = CreditsFacade.GetCreditsUserGroupId(userInfo.Credits); Users.UpdateUserGroup(userInfo.Uid, userInfo.Groupid); } #endregion if (userInfo.Groupid == 5 || userInfo.Groupid == 8)// 5-禁止访问或者需要激活帐号的用户 { result = Util.CreateErrorMessage(ErrorType.API_EC_BANNED_USERGROUP, commandParam.ParamList); return false; } #region 无延迟更新在线信息和相关用户信息 ForumUtils.WriteUserCookie(userInfo.Uid, expires, commandParam.GeneralConfig.Passwordkey, 0, -1); OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(commandParam.GeneralConfig.Passwordkey, commandParam.GeneralConfig.Onlinetimeout, userInfo.Uid, ""); OnlineUsers.UpdateAction(oluserinfo.Olid, UserAction.Login.ActionID, 0); LoginLogs.DeleteLoginLog(DNTRequest.GetIP()); Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP()); #endregion result = "success"; result = commandParam.Format == FormatType.JSON ? string.Format("\"{0}\"", result) : SerializationHelper.Serialize(result); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string password = commandParam.GetDNTParam("password").ToString(); bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString() == "md5" ? true : false; EncodePasswordResponse epr = new EncodePasswordResponse(); epr.Password = Utils.UrlEncode(ForumUtils.SetCookiePassword(isMD5Passwd ? password : Utils.MD5(password), commandParam.GeneralConfig.Passwordkey)); result = commandParam.Format == FormatType.JSON ? string.Format("\"{0}\"", epr.Password) : SerializationHelper.Serialize(epr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (!commandParam.CheckRequiredParams("user_name,password,email")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP)//如果是桌面程序则不允许此方法 { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } ShortUserInfo shortUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (shortUserInfo == null || shortUserInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } else if (commandParam.LocalUid > 0)//已经登录的用户不能再注册 { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ONLINE, commandParam.ParamList); return false; } string username = commandParam.GetDNTParam("user_name").ToString(); string password = commandParam.GetDNTParam("password").ToString(); string email = commandParam.GetDNTParam("email").ToString(); bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString() == "md5" ? true : false; //用户名不符合规范 if (!AuthCommandUtils.CheckUsername(username)) { result = Util.CreateErrorMessage(ErrorType.API_EC_USERNAME_ILLEGAL, commandParam.ParamList); return false; } if (Discuz.Forum.Users.GetUserId(username) != 0)//如果用户名符合注册规则, 则判断是否已存在 { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ALREADY_EXIST, commandParam.ParamList); return false; } if (!isMD5Passwd && password.Length < 6) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (!AuthCommandUtils.CheckEmail(email, commandParam.GeneralConfig)) { result = Util.CreateErrorMessage(ErrorType.API_EC_EMAIL, commandParam.ParamList); return false; } #region Create New UserInfo UserInfo userInfo = new UserInfo(); userInfo.Username = username; userInfo.Nickname = string.Empty; userInfo.Password = isMD5Passwd ? password : Utils.MD5(password); userInfo.Secques = string.Empty; userInfo.Gender = 0; userInfo.Adminid = 0; userInfo.Groupexpiry = 0; userInfo.Extgroupids = ""; userInfo.Regip = DNTRequest.GetIP(); userInfo.Joindate = Utils.GetDateTime(); userInfo.Lastip = DNTRequest.GetIP(); userInfo.Lastvisit = Utils.GetDateTime(); userInfo.Lastactivity = Utils.GetDateTime(); userInfo.Lastpost = Utils.GetDateTime(); userInfo.Lastpostid = 0; userInfo.Lastposttitle = ""; userInfo.Posts = 0; userInfo.Digestposts = 0; userInfo.Oltime = 0; userInfo.Pageviews = 0; userInfo.Credits = 0; userInfo.Extcredits1 = Scoresets.GetScoreSet(1).Init; userInfo.Extcredits2 = Scoresets.GetScoreSet(2).Init; userInfo.Extcredits3 = Scoresets.GetScoreSet(3).Init; userInfo.Extcredits4 = Scoresets.GetScoreSet(4).Init; userInfo.Extcredits5 = Scoresets.GetScoreSet(5).Init; userInfo.Extcredits6 = Scoresets.GetScoreSet(6).Init; userInfo.Extcredits7 = Scoresets.GetScoreSet(7).Init; userInfo.Extcredits8 = Scoresets.GetScoreSet(8).Init; userInfo.Email = email; userInfo.Bday = string.Empty; userInfo.Sigstatus = 0; userInfo.Tpp = 0; userInfo.Ppp = 0; userInfo.Templateid = 0; userInfo.Pmsound = 0; userInfo.Showemail = 0; userInfo.Salt = "0"; int receivepmsetting = commandParam.GeneralConfig.Regadvance == 0 ? 7 : 1; userInfo.Newsletter = (ReceivePMSettingType)receivepmsetting; userInfo.Invisible = 0; userInfo.Newpm = commandParam.GeneralConfig.Welcomemsg == 1 ? 1 : 0; userInfo.Medals = ""; userInfo.Accessmasks = 0; userInfo.Website = string.Empty; userInfo.Icq = string.Empty; userInfo.Qq = string.Empty; userInfo.Yahoo = string.Empty; userInfo.Msn = string.Empty; userInfo.Skype = string.Empty; userInfo.Location = string.Empty; userInfo.Customstatus = string.Empty; userInfo.Bio = string.Empty; userInfo.Signature = string.Empty; userInfo.Sightml = string.Empty; userInfo.Authtime = Utils.GetDateTime(); //邮箱激活链接验证 if (commandParam.GeneralConfig.Regverify == 1) { userInfo.Authstr = ForumUtils.CreateAuthStr(20); userInfo.Authflag = 1; userInfo.Groupid = 8; Emails.DiscuzSmtpMail(username, email, string.Empty, userInfo.Authstr); } //系统管理员进行后台验证 else if (commandParam.GeneralConfig.Regverify == 2) { userInfo.Authstr = string.Empty; userInfo.Groupid = 8; userInfo.Authflag = 1; } else { userInfo.Authstr = ""; userInfo.Authflag = 0; userInfo.Groupid = CreditsFacade.GetCreditsUserGroupId(0).Groupid; } userInfo.Realname = string.Empty; userInfo.Idcard = string.Empty; userInfo.Mobile = string.Empty; userInfo.Phone = string.Empty; if (commandParam.GeneralConfig.Passwordmode > 1 && PasswordModeProvider.GetInstance() != null) { userInfo.Uid = PasswordModeProvider.GetInstance().CreateUserInfo(userInfo); } else { userInfo.Uid = Discuz.Forum.Users.CreateUser(userInfo); } #endregion if (commandParam.GeneralConfig.Welcomemsg == 1) { PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo(); // 收件箱 privatemessageinfo.Message = commandParam.GeneralConfig.Welcomemsgtxt; privatemessageinfo.Subject = "欢迎您的加入! (请勿回复本信息)"; privatemessageinfo.Msgto = userInfo.Username; privatemessageinfo.Msgtoid = userInfo.Uid; privatemessageinfo.Msgfrom = PrivateMessages.SystemUserName; privatemessageinfo.Msgfromid = 0; privatemessageinfo.New = 1; privatemessageinfo.Postdatetime = Utils.GetDateTime(); privatemessageinfo.Folder = 0; PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0); } Statistics.ReSetStatisticsCache(); //信息同步通知不会发向当前请求接口的应用程序,所以此处应保留,以支持论坛向其他关联应用程序发送通知 Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, commandParam.AppInfo.APIKey); CreditsFacade.UpdateUserCredits(userInfo.Uid); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", userInfo.Uid); else { RegisterResponse rr = new RegisterResponse(); rr.Uid = userInfo.Uid; result = SerializationHelper.Serialize(rr); } return true; }
/* * Description: * 桌面程序强制validate=true,且必须是在线用户 */ public override bool Run(CommandParameter commandParam, ref string result) { //桌面程序因为安全需要,游客不允许操作 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } //如果validate为true,则校验数据的合法性,包括广告强力屏蔽,是否含有需审核的,以及非法内容.和当前用户的发帖权限,桌面程序强制验证 bool validate = commandParam.GetIntParam("validate") == 1 || commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP; if (!commandParam.CheckRequiredParams("topic_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } Topic topic; try { topic = JavaScriptConvert.DeserializeObject<Topic>(commandParam.GetDNTParam("topic_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (topic == null || Util.AreParamsNullOrZeroOrEmptyString(topic.Fid, topic.Title, topic.Message)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } //文档中应说明title长度范围和内容范围 if (topic.Title.Length > 60) { result = Util.CreateErrorMessage(ErrorType.API_EC_TITLE_INVALID, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topic.Fid ?? 0); if (forumInfo == null || forumInfo.Layer == 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } //如果validate为true,则强制读取当前用户 ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(validate || (topic.UId == null) ? commandParam.LocalUid : (int)topic.UId); userInfo = userInfo == null ? TopicsCommandUtils.GetGuestUserInfo() : userInfo; UserGroupInfo userGroupInfo = UserGroups.GetUserGroupInfo(userInfo.Groupid); AdminGroupInfo adminInfo = AdminGroups.GetAdminGroupInfo(userGroupInfo.Groupid); //是否受审核、过滤、灌水等限制权限 int disablePost = adminInfo != null ? adminInfo.Disablepostctrl : userGroupInfo.Disableperiodctrl; bool hasAudit = false; if (validate) { ErrorType et = TopicsCommandUtils.GeneralValidate(topic.Title, topic.Message, userInfo, userGroupInfo, forumInfo, commandParam, disablePost); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } string str = ""; //是否允许发主题 if (!UserAuthority.PostAuthority(forumInfo, userGroupInfo, userInfo.Uid, ref str)) { result = Util.CreateErrorMessage(ErrorType.API_EC_POST_PERM, commandParam.ParamList); return false; } if (disablePost != 1) { et = TopicsCommandUtils.PostTimeAndRepostMessageValidate(userInfo, topic.Title + topic.Message); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //内容中是否含有需审核的词汇 if (ForumUtils.HasAuditWord(topic.Title + topic.Message)) hasAudit = true; //过滤非法词汇 topic.Title = ForumUtils.BanWordFilter(topic.Title); topic.Message = ForumUtils.BanWordFilter(topic.Message); } } //主题图标id int iconId = topic.Iconid ?? 0; //图标id值域仅为0-15 iconId = (iconId > 15 || iconId < 0) ? 0 : iconId; TopicInfo topicInfo = new TopicInfo(); topicInfo.Fid = forumInfo.Fid; topicInfo.Iconid = iconId; topicInfo.Title = Utils.HtmlEncode(topic.Title); bool htmlon = topic.Message.Length != Utils.RemoveHtml(topic.Message).Length && userGroupInfo.Allowhtml == 1; //支持html标签? if (!htmlon) topic.Message = Utils.HtmlEncode(topic.Message); string curDateTime = Utils.GetDateTime(); //发帖主题分类校验和绑定 topicInfo.Typeid = 0; if (forumInfo.Applytopictype == 1) { if (Discuz.Forum.Forums.IsCurrentForumTopicType(topic.Typeid.ToString(), forumInfo.Topictypes)) topicInfo.Typeid = (int)topic.Typeid; else if (forumInfo.Postbytopictype == 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } } topicInfo.Readperm = 0; topicInfo.Price = 0; topicInfo.Poster = userInfo.Username; topicInfo.Posterid = userInfo.Uid; topicInfo.Postdatetime = curDateTime; topicInfo.Lastpost = curDateTime; topicInfo.Lastposter = userInfo.Username; topicInfo.Views = 0; topicInfo.Replies = 0; topicInfo.Displayorder = (forumInfo.Modnewtopics == 1) ? -2 : 0; if (topicInfo.Displayorder != -2 && (hasAudit || Scoresets.BetweenTime(commandParam.GeneralConfig.Postmodperiods))) topicInfo.Displayorder = -2; topicInfo.Highlight = ""; topicInfo.Digest = 0; topicInfo.Rate = 0; topicInfo.Hide = 0; topicInfo.Attachment = 0; topicInfo.Moderated = 0; topicInfo.Closed = 0; string tags = string.Empty; string[] tagArray = null; //是否使用tag bool enableTag = (commandParam.GeneralConfig.Enabletag & forumInfo.Allowtag) == 1; if (!string.IsNullOrEmpty(topic.Tags)) { //标签(Tag)操作 tags = topic.Tags.Trim(); tagArray = Utils.SplitString(tags, ",", true, 2, 10); if (enableTag) { if (topicInfo.Magic == 0) topicInfo.Magic = 10000; topicInfo.Magic = Utils.StrToInt(topicInfo.Magic.ToString() + "1", 0); } } int topicId = Discuz.Forum.Topics.CreateTopic(topicInfo); if (enableTag && tagArray != null && tagArray.Length > 0) { //若当前用户不受过滤,审核约束 if (!validate || disablePost == 1 || !ForumUtils.HasBannedWord(tags)) ForumTags.CreateTopicTags(tagArray, topicId, userInfo.Uid, curDateTime); } PostInfo postInfo = new PostInfo(); postInfo.Fid = forumInfo.Fid; postInfo.Tid = topicId; postInfo.Parentid = 0; postInfo.Layer = 0; postInfo.Poster = userInfo.Username; postInfo.Posterid = userInfo.Uid; postInfo.Title = topicInfo.Title; postInfo.Postdatetime = curDateTime; postInfo.Message = topic.Message; postInfo.Ip = DNTRequest.GetIP(); postInfo.Lastedit = ""; postInfo.Invisible = topicInfo.Displayorder == -2 ? 1 : 0; postInfo.Usesig = 0; postInfo.Htmlon = htmlon ? 1 : 0; postInfo.Smileyoff = 1 - forumInfo.Allowsmilies; postInfo.Bbcodeoff = 1; if (userGroupInfo.Allowcusbbcode == 1 && forumInfo.Allowbbcode == 1) postInfo.Bbcodeoff = 0; postInfo.Parseurloff = 0; postInfo.Attachment = 0; postInfo.Rate = 0; postInfo.Ratetimes = 0; postInfo.Topictitle = topicInfo.Title; int postid = 0; try { postid = Posts.CreatePost(postInfo); } catch { TopicAdmins.DeleteTopics(topicId.ToString(), false); result = Util.CreateErrorMessage(ErrorType.API_EC_UNKNOWN, commandParam.ParamList); return false; } Discuz.Forum.Topics.AddParentForumTopics(forumInfo.Parentidlist.Trim(), 1); TopicCreateResponse tcr = new TopicCreateResponse(); tcr.TopicId = topicId; tcr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topicId, 0); tcr.NeedAudit = topicInfo.Displayorder == -2; #region 更新积分 //设置用户的积分 ///首先读取版块内自定义积分 ///版设置了自定义积分则使用,否则使用论坛默认积分 //float[] values = null; //if (!string.IsNullOrEmpty(forumInfo.Postcredits)) //{ // int index = 0; // float tempval = 0; // values = new float[8]; // foreach (string ext in Utils.SplitString(forumInfo.Postcredits, ",")) // { // if (index == 0) // { // if (!ext.Equals("True")) // { // values = null; // break; // } // index++; // continue; // } // tempval = Utils.StrToFloat(ext, 0); // values[index - 1] = tempval; // index++; // if (index > 8) // break; // } //} if (userInfo.Adminid == 1 || !tcr.NeedAudit) CreditsFacade.PostTopic(userInfo.Uid, forumInfo); //TopicsCommandUtils.UpdateScore(userInfo.Uid, values); #endregion //同步到其他应用程序 Sync.NewTopic(topicId.ToString(), topicInfo.Title, topicInfo.Poster, topicInfo.Posterid.ToString(), topicInfo.Fid.ToString(), commandParam.AppInfo.APIKey); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tcr) : SerializationHelper.Serialize(tcr); return true; }
/* * Description: * 每个用户UID 15秒内只能调用一次该接口,否则无法更新成功 */ public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } if (Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("uids,additional_values")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string[] values = commandParam.GetDNTParam("additional_values").ToString().Split(','); string[] uids = commandParam.GetDNTParam("uids").ToString().Split(','); if (!Utils.IsNumericArray(uids) || !Utils.IsNumericArray(values) || uids.Length > 100) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (values.Length != 8) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } List <float> list = new List <float>(); for (int i = 0; i < values.Length; i++) { list.Add(Utils.StrToFloat(values[i], 0)); } foreach (string uId in uids) { int id = TypeConverter.StrToInt(uId); if (id == 0) { continue; } if (!CommandCacheQueue <SetExtCreditItem> .EnQueue(new SetExtCreditItem(id, DateTime.Now.Ticks))) { continue; } CreditsFacade.UpdateUserExtCredits(id, list.ToArray(), true); CreditsFacade.UpdateUserCredits(id); //向第三方应用同步积分 for (int i = 0; i < list.Count; i++) { if (list[i] != 0.0) { Sync.UpdateCredits(TypeConverter.StrToInt(uId), i + 1, list[i].ToString(), commandParam.AppInfo.APIKey); } } } if (commandParam.Format == FormatType.JSON) { result = "true"; } else { SetExtCreditsResponse secr = new SetExtCreditsResponse(); secr.Successfull = 1; result = SerializationHelper.Serialize(secr); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果validate为true,则校验数据的合法性,包括广告强力屏蔽,是否含有需审核的,以及非法内容.和当前用户的发帖权限 bool validate = commandParam.GetIntParam("validate") == 1 || commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP; //桌面程序因为安全需要,游客不允许操作 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("reply_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } Reply reply; try { reply = JavaScriptConvert.DeserializeObject<Reply>(commandParam.GetDNTParam("reply_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (reply == null || Util.AreParamsNullOrZeroOrEmptyString(reply.Tid, reply.Fid, reply.Message)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (reply.Title == null) reply.Title = string.Empty; if (reply.Title.IndexOf(" ") != -1 || reply.Title.Length > 60) { result = Util.CreateErrorMessage(ErrorType.API_EC_TITLE_INVALID, commandParam.ParamList); return false; } if (reply.Message.Length < commandParam.GeneralConfig.Minpostsize || reply.Message.Length > commandParam.GeneralConfig.Maxpostsize) { result = Util.CreateErrorMessage(ErrorType.API_EC_MESSAGE_LENGTH, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(reply.Fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(reply.Tid); if (topicInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList); return false; } //validate=true或未指定回帖uid时则默认读取当前用户uid,游客为-1 ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(validate || reply.Uid == null ? commandParam.LocalUid : (int)reply.Uid); userInfo = userInfo == null ? TopicsCommandUtils.GetGuestUserInfo() : userInfo; UserGroupInfo userGroupInfo = Discuz.Forum.UserGroups.GetUserGroupInfo(userInfo.Groupid); AdminGroupInfo adminInfo = AdminGroups.GetAdminGroupInfo(userGroupInfo.Groupid); //是否受审核、过滤、灌水等限制权限 int disablePost = adminInfo != null ? adminInfo.Disablepostctrl : userGroupInfo.Disableperiodctrl; bool hasAudit = false; if (validate) { ErrorType et = TopicsCommandUtils.GeneralValidate(reply.Title, reply.Message, userInfo, userGroupInfo, forumInfo, commandParam, disablePost); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //是否有回复的权限 if (!UserAuthority.PostReply(forumInfo, commandParam.LocalUid, userGroupInfo, topicInfo)) { result = Util.CreateErrorMessage(topicInfo.Closed >= 1 ? ErrorType.API_EC_TOPIC_CLOSED : ErrorType.API_EC_REPLY_PERM, commandParam.ParamList); return false; } if (disablePost != 1) { et = TopicsCommandUtils.PostTimeAndRepostMessageValidate(userInfo, reply.Title + reply.Message); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //内容中是否含有需审核的词汇 if (ForumUtils.HasAuditWord(reply.Title + reply.Message)) hasAudit = true; reply.Title = ForumUtils.BanWordFilter(reply.Title); reply.Message = ForumUtils.BanWordFilter(reply.Message); } } PostInfo postInfo = TopicsCommandUtils.PostReply(reply, userGroupInfo, userInfo, forumInfo, topicInfo.Title, disablePost, hasAudit); if (topicInfo.Replies < (commandParam.GeneralConfig.Ppp + 9)) { ForumUtils.DeleteTopicCacheFile(topicInfo.Tid); } TopicReplyResponse trr = new TopicReplyResponse(); trr.PostId = postInfo.Pid; trr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + string.Format("showtopic.aspx?topicid={0}&postid={1}#{1}", reply.Tid, trr.PostId); trr.NeedAudit = postInfo.Invisible == 1; //同步到其他应用程序 Sync.Reply(postInfo.Pid.ToString(), postInfo.Tid.ToString(), postInfo.Topictitle, postInfo.Poster, postInfo.Posterid.ToString(), postInfo.Fid.ToString(), commandParam.AppInfo.APIKey); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(trr) : SerializationHelper.Serialize(trr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 //if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) //{ // if (commandParam.LocalUid < 1) // { // result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); // return false; // } //} if (!commandParam.CheckRequiredParams("fid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = Utils.StrToInt(commandParam.GetDNTParam("fid"), 0); if (fid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } ForumGetResponse fgr = new ForumGetResponse(); fgr.Fid = fid; fgr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Urls.ShowForumAspxRewrite(fid, 1, forumInfo.Rewritename); fgr.CurTopics = forumInfo.CurrentTopics; fgr.Description = forumInfo.Description; fgr.Icon = forumInfo.Icon; fgr.LastPost = forumInfo.Lastpost; fgr.LastPoster = forumInfo.Lastposter.Trim(); fgr.LastPosterId = forumInfo.Lastposterid; fgr.LastTid = forumInfo.Lasttid; fgr.LastTitle = forumInfo.Lasttitle.Trim(); fgr.Moderators = forumInfo.Moderators; fgr.Name = forumInfo.Name; fgr.ParentId = forumInfo.Parentid; fgr.ParentIdList = forumInfo.Parentidlist.Trim(); fgr.PathList = forumInfo.Pathlist.Trim(); fgr.Posts = forumInfo.Posts; fgr.Rules = forumInfo.Rules; fgr.Status = forumInfo.Status; fgr.SubForumCount = forumInfo.Subforumcount; fgr.TodayPosts = forumInfo.Todayposts; fgr.Topics = forumInfo.Topics; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(fgr) : SerializationHelper.Serialize(fgr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("fid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = commandParam.GetIntParam("fid"); ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Tpp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Tpp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; //主题分类条件idlist string topicTypeIdList = commandParam.GetDNTParam("type_id_list").ToString(); string condition = string.Empty;//查询主题的条件 //如果条件不为空且是逗号分割的list,则添加condition条件 if (!string.IsNullOrEmpty(topicTypeIdList) && Utils.IsNumericList(topicTypeIdList)) condition = " AND [typeid] IN (" + topicTypeIdList + ") "; int count = Discuz.Forum.Topics.GetTopicCount(fid, true, string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetTopicList(fid, pageSize, pageIndex, 0, 600, commandParam.GeneralConfig.Hottopic, forumInfo.Autoclose, forumInfo.Topictypeprefix, condition); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tglr) : SerializationHelper.Serialize(tglr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("user_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } UserForEditing ufe; try { ufe = JavaScriptConvert.DeserializeObject<UserForEditing>(commandParam.GetDNTParam("user_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } #region 用户信息读取及权限校验 int uid = commandParam.GetIntParam("uid"); uid = uid > 0 ? uid : commandParam.LocalUid; if (uid <= 0) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } UserInfo localUserInfo = null; //终端应用程序需要校验当前用户权限,不是管理员则只能修改自己的资料 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { localUserInfo = Users.GetUserInfo(commandParam.LocalUid); if (localUserInfo == null || (localUserInfo.Uid != uid && localUserInfo.Adminid != 1)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } UserInfo userInfo = localUserInfo != null && localUserInfo.Uid == uid ? localUserInfo : Users.GetUserInfo(uid); if (userInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return false; } #endregion if (!string.IsNullOrEmpty(ufe.Email)) { if (!UserCommandUtils.CheckEmail(ufe.Email, commandParam.GeneralConfig.Accessemail)) { result = Util.CreateErrorMessage(ErrorType.API_EC_EMAIL, commandParam.ParamList); return false; } userInfo.Email = ufe.Email; } if (!string.IsNullOrEmpty(ufe.Password)) userInfo.Password = ufe.Password; if (!string.IsNullOrEmpty(ufe.Bio)) userInfo.Bio = ufe.Bio; if (!string.IsNullOrEmpty(ufe.Birthday)) userInfo.Bday = ufe.Birthday; if (!string.IsNullOrEmpty(ufe.ExtCredits1)) userInfo.Extcredits1 = Utils.StrToFloat(ufe.ExtCredits1, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits2)) userInfo.Extcredits2 = Utils.StrToFloat(ufe.ExtCredits2, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits3)) userInfo.Extcredits3 = Utils.StrToFloat(ufe.ExtCredits3, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits4)) userInfo.Extcredits4 = Utils.StrToFloat(ufe.ExtCredits4, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits5)) userInfo.Extcredits5 = Utils.StrToFloat(ufe.ExtCredits5, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits6)) userInfo.Extcredits6 = Utils.StrToFloat(ufe.ExtCredits6, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits7)) userInfo.Extcredits7 = Utils.StrToFloat(ufe.ExtCredits7, 0); if (!string.IsNullOrEmpty(ufe.ExtCredits8)) userInfo.Extcredits8 = Utils.StrToFloat(ufe.ExtCredits8, 0); if (!string.IsNullOrEmpty(ufe.Gender)) userInfo.Gender = Utils.StrToInt(ufe.Gender, 0); if (!string.IsNullOrEmpty(ufe.Icq)) userInfo.Icq = ufe.Icq; if (!string.IsNullOrEmpty(ufe.IdCard)) userInfo.Idcard = ufe.IdCard; if (!string.IsNullOrEmpty(ufe.Location)) userInfo.Location = ufe.Location; if (!string.IsNullOrEmpty(ufe.Mobile)) userInfo.Mobile = ufe.Mobile; if (!string.IsNullOrEmpty(ufe.Msn)) userInfo.Msn = ufe.Msn; if (!string.IsNullOrEmpty(ufe.NickName)) userInfo.Nickname = ufe.NickName; if (!string.IsNullOrEmpty(ufe.Phone)) userInfo.Phone = ufe.Phone; if (!string.IsNullOrEmpty(ufe.Qq)) userInfo.Qq = ufe.Qq; if (!string.IsNullOrEmpty(ufe.RealName)) userInfo.Realname = ufe.RealName; if (!string.IsNullOrEmpty(ufe.Skype)) userInfo.Skype = ufe.Skype; if (!string.IsNullOrEmpty(ufe.SpaceId)) userInfo.Spaceid = Utils.StrToInt(ufe.SpaceId, 0); if (!string.IsNullOrEmpty(ufe.WebSite)) userInfo.Website = ufe.WebSite; if (!string.IsNullOrEmpty(ufe.Yahoo)) userInfo.Yahoo = ufe.Yahoo; try { Users.UpdateUser(userInfo); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_UNKNOWN, commandParam.ParamList); return false; } if (commandParam.Format == FormatType.JSON) result = "true"; else { SetInfoResponse sir = new SetInfoResponse(); sir.Successfull = 1; result = SerializationHelper.Serialize(sir); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (!commandParam.CheckRequiredParams("topic_ids")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string topicIds = commandParam.GetDNTParam("topic_ids").ToString(); if (!Utils.IsNumericList(topicIds)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (topicIds.Split(',').Length > 20) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int forumId = commandParam.GetIntParam("fid"); //桌面程序需要验证当前登录用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (!commandParam.CheckRequiredParams("fid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } ShortUserInfo user = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid); if (user == null || !Moderators.IsModer(user.Adminid, commandParam.LocalUid, forumId)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } if (!Discuz.Forum.Topics.InSameForum(topicIds, forumId)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } } bool deleteResult = Discuz.Forum.TopicAdmins.DeleteTopics(topicIds, false) > 0; TopicDeleteResponse tdr = new TopicDeleteResponse(); tdr.Successfull = deleteResult ? 1 : 0; result = commandParam.Format == FormatType.JSON ? string.Format("\"{0}\"", result.ToString().ToLower()) : SerializationHelper.Serialize(tdr); return true; }
/* * Description: * 每个用户UID 15秒内只能调用一次该接口,否则无法更新成功 */ public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("uids,additional_values")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string[] values = commandParam.GetDNTParam("additional_values").ToString().Split(','); string[] uids = commandParam.GetDNTParam("uids").ToString().Split(','); if (!Utils.IsNumericArray(uids) || !Utils.IsNumericArray(values) || uids.Length > 100) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (values.Length != 8) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } List<float> list = new List<float>(); for (int i = 0; i < values.Length; i++) { list.Add(Utils.StrToFloat(values[i], 0)); } foreach (string uId in uids) { int id = TypeConverter.StrToInt(uId); if (id == 0) continue; if (!CommandCacheQueue<SetExtCreditItem>.EnQueue(new SetExtCreditItem(id, DateTime.Now.Ticks))) continue; CreditsFacade.UpdateUserExtCredits(id, list.ToArray(), true); CreditsFacade.UpdateUserCredits(id); //向第三方应用同步积分 for (int i = 0; i < list.Count; i++) { if (list[i] != 0.0) Sync.UpdateCredits(TypeConverter.StrToInt(uId), i + 1, list[i].ToString(), commandParam.AppInfo.APIKey); } } if (commandParam.Format == FormatType.JSON) result = "true"; else { SetExtCreditsResponse secr = new SetExtCreditsResponse(); secr.Successfull = 1; result = SerializationHelper.Serialize(secr); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("tid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int tid = commandParam.GetIntParam("tid"); TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid); if (topicInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topicInfo.Fid); int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Tpp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Tpp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; PostpramsInfo postPramsInfo = TopicsCommandUtils.GetPostParamInfo(commandParam.LocalUid, topicInfo, forumInfo, pageSize, pageIndex); List<ShowtopicPageAttachmentInfo> attachmentList = new List<ShowtopicPageAttachmentInfo>(); List<ShowtopicPagePostInfo> postList = Posts.GetPostList(postPramsInfo, out attachmentList, false); List<Post> list = new List<Post>(); foreach (ShowtopicPagePostInfo postInfo in postList) { Post post = new Post(); post.AdIndex = postInfo.Adindex; post.Invisible = postInfo.Invisible; post.Layer = postInfo.Layer; post.Message = postInfo.Message; post.Pid = postInfo.Pid; post.PostDateTime = postInfo.Postdatetime; post.PosterAvator = postInfo.Avatar; post.PosterAvatorWidth = postInfo.Avatarwidth; post.PosterAvatorHeight = postInfo.Avatarheight; post.PosterEmail = postInfo.Email; post.PosterId = postInfo.Posterid; post.PosterLocation = postInfo.Location; post.PosterName = postInfo.Poster; post.PosterShowEmail = postInfo.Showemail; post.PosterSignature = postInfo.Signature; post.Rate = postInfo.Rate; post.RateTimes = postInfo.Ratetimes; post.UseSignature = postInfo.Usesig; list.Add(post); } TopicGetResponse tgr = new TopicGetResponse(); tgr.Author = topicInfo.Poster; tgr.AuthorId = topicInfo.Posterid; tgr.Fid = topicInfo.Fid; tgr.Iconid = topicInfo.Iconid; tgr.LastPosterId = topicInfo.Lastposterid; tgr.LastPostTime = topicInfo.Lastpost; tgr.List = list.Count > 1; tgr.ReplyCount = topicInfo.Replies; tgr.Tags = ForumTags.GetTagsByTopicId(topicInfo.Tid); tgr.Title = topicInfo.Title; tgr.TopicId = topicInfo.Tid; tgr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topicInfo.Tid, 0); tgr.ViewCount = topicInfo.Views; tgr.TypeId = topicInfo.Typeid; SortedList<int, string> topicTypeList = Caches.GetTopicTypeArray(); topicTypeList.TryGetValue(topicInfo.Typeid, out tgr.TypeName); tgr.Posts = list.ToArray(); tgr.Attachments = TopicsCommandUtils.ConvertAttachmentArray(attachmentList); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tgr) : Util.AddTitleCDATA(Util.AddMessageCDATA(SerializationHelper.Serialize(tgr))); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (!commandParam.CheckRequiredParams("user_name,password,email")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP)//如果是桌面程序则不允许此方法 { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } ShortUserInfo shortUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (shortUserInfo == null || shortUserInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } else if (commandParam.LocalUid > 0)//已经登录的用户不能再注册 { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ONLINE, commandParam.ParamList); return(false); } string username = commandParam.GetDNTParam("user_name").ToString(); string password = commandParam.GetDNTParam("password").ToString(); string email = commandParam.GetDNTParam("email").ToString(); bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString() == "md5" ? true : false; //用户名不符合规范 if (!AuthCommandUtils.CheckUsername(username)) { result = Util.CreateErrorMessage(ErrorType.API_EC_USERNAME_ILLEGAL, commandParam.ParamList); return(false); } if (Discuz.Forum.Users.GetUserId(username) != 0)//如果用户名符合注册规则, 则判断是否已存在 { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_ALREADY_EXIST, commandParam.ParamList); return(false); } if (!isMD5Passwd && password.Length < 6) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (!AuthCommandUtils.CheckEmail(email, commandParam.GeneralConfig)) { result = Util.CreateErrorMessage(ErrorType.API_EC_EMAIL, commandParam.ParamList); return(false); } #region Create New UserInfo UserInfo userInfo = new UserInfo(); userInfo.Username = username; userInfo.Nickname = string.Empty; userInfo.Password = isMD5Passwd ? password : Utils.MD5(password); userInfo.Secques = string.Empty; userInfo.Gender = 0; userInfo.Adminid = 0; userInfo.Groupexpiry = 0; userInfo.Extgroupids = ""; userInfo.Regip = DNTRequest.GetIP(); userInfo.Joindate = Utils.GetDateTime(); userInfo.Lastip = DNTRequest.GetIP(); userInfo.Lastvisit = Utils.GetDateTime(); userInfo.Lastactivity = Utils.GetDateTime(); userInfo.Lastpost = Utils.GetDateTime(); userInfo.Lastpostid = 0; userInfo.Lastposttitle = ""; userInfo.Posts = 0; userInfo.Digestposts = 0; userInfo.Oltime = 0; userInfo.Pageviews = 0; userInfo.Credits = 0; userInfo.Extcredits1 = Scoresets.GetScoreSet(1).Init; userInfo.Extcredits2 = Scoresets.GetScoreSet(2).Init; userInfo.Extcredits3 = Scoresets.GetScoreSet(3).Init; userInfo.Extcredits4 = Scoresets.GetScoreSet(4).Init; userInfo.Extcredits5 = Scoresets.GetScoreSet(5).Init; userInfo.Extcredits6 = Scoresets.GetScoreSet(6).Init; userInfo.Extcredits7 = Scoresets.GetScoreSet(7).Init; userInfo.Extcredits8 = Scoresets.GetScoreSet(8).Init; userInfo.Email = email; userInfo.Bday = string.Empty; userInfo.Sigstatus = 0; userInfo.Tpp = 0; userInfo.Ppp = 0; userInfo.Templateid = 0; userInfo.Pmsound = 0; userInfo.Showemail = 0; userInfo.Salt = "0"; int receivepmsetting = commandParam.GeneralConfig.Regadvance == 0 ? 7 : 1; userInfo.Newsletter = (ReceivePMSettingType)receivepmsetting; userInfo.Invisible = 0; userInfo.Newpm = commandParam.GeneralConfig.Welcomemsg == 1 ? 1 : 0; userInfo.Medals = ""; userInfo.Accessmasks = 0; userInfo.Website = string.Empty; userInfo.Icq = string.Empty; userInfo.Qq = string.Empty; userInfo.Yahoo = string.Empty; userInfo.Msn = string.Empty; userInfo.Skype = string.Empty; userInfo.Location = string.Empty; userInfo.Customstatus = string.Empty; userInfo.Bio = string.Empty; userInfo.Signature = string.Empty; userInfo.Sightml = string.Empty; userInfo.Authtime = Utils.GetDateTime(); //邮箱激活链接验证 if (commandParam.GeneralConfig.Regverify == 1) { userInfo.Authstr = ForumUtils.CreateAuthStr(20); userInfo.Authflag = 1; userInfo.Groupid = 8; Emails.DiscuzSmtpMail(username, email, string.Empty, userInfo.Authstr); } //系统管理员进行后台验证 else if (commandParam.GeneralConfig.Regverify == 2) { userInfo.Authstr = string.Empty; userInfo.Groupid = 8; userInfo.Authflag = 1; } else { userInfo.Authstr = ""; userInfo.Authflag = 0; userInfo.Groupid = CreditsFacade.GetCreditsUserGroupId(0).Groupid; } userInfo.Realname = string.Empty; userInfo.Idcard = string.Empty; userInfo.Mobile = string.Empty; userInfo.Phone = string.Empty; if (commandParam.GeneralConfig.Passwordmode > 1 && PasswordModeProvider.GetInstance() != null) { userInfo.Uid = PasswordModeProvider.GetInstance().CreateUserInfo(userInfo); } else { userInfo.Uid = Discuz.Forum.Users.CreateUser(userInfo); } #endregion if (commandParam.GeneralConfig.Welcomemsg == 1) { PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo(); // 收件箱 privatemessageinfo.Message = commandParam.GeneralConfig.Welcomemsgtxt; privatemessageinfo.Subject = "欢迎您的加入! (请勿回复本信息)"; privatemessageinfo.Msgto = userInfo.Username; privatemessageinfo.Msgtoid = userInfo.Uid; privatemessageinfo.Msgfrom = PrivateMessages.SystemUserName; privatemessageinfo.Msgfromid = 0; privatemessageinfo.New = 1; privatemessageinfo.Postdatetime = Utils.GetDateTime(); privatemessageinfo.Folder = 0; PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0); } Statistics.ReSetStatisticsCache(); //信息同步通知不会发向当前请求接口的应用程序,所以此处应保留,以支持论坛向其他关联应用程序发送通知 Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, commandParam.AppInfo.APIKey); CreditsFacade.UpdateUserCredits(userInfo.Uid); if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", userInfo.Uid); } else { RegisterResponse rr = new RegisterResponse(); rr.Uid = userInfo.Uid; result = SerializationHelper.Serialize(rr); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } ShortUserInfo userInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (userInfo == null || userInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("forum_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } Forum forum; try { forum = JavaScriptConvert.DeserializeObject<Forum>(commandParam.GetDNTParam("forum_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (forum == null || string.IsNullOrEmpty(forum.Name)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (!Utils.StrIsNullOrEmpty(forum.RewriteName) && Discuz.Forum.Forums.CheckRewriteNameInvalid(forum.RewriteName)) { result = Util.CreateErrorMessage(ErrorType.API_EC_REWRITENAME, commandParam.ParamList); return false; } int fid; if (forum.ParentId > 0) { #region 添加与当前论坛同级的论坛 //添加与当前论坛同级的论坛 ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(forum.ParentId); //找出当前要插入的记录所用的FID string parentidlist = null; parentidlist = forumInfo.Parentidlist == "0" ? forumInfo.Fid.ToString() : forumInfo.Parentidlist + "," + forumInfo.Fid; DataTable dt = AdminForums.GetMaxDisplayOrder(forum.ParentId); int maxdisplayorder = (dt.Rows.Count > 0) && (dt.Rows[0][0].ToString() != "") ? Convert.ToInt32(dt.Rows[0][0]) : forumInfo.Displayorder; AdminForums.UpdateForumsDisplayOrder(maxdisplayorder); fid = ForumsCommandUtils.InsertForum(forum, forumInfo.Layer + 1, parentidlist, 0, maxdisplayorder + 1); AdminForums.SetSubForumCount(forumInfo.Fid); #endregion } else { #region 按根论坛插入 int maxdisplayorder = AdminForums.GetMaxDisplayOrder(); fid = ForumsCommandUtils.InsertForum(forum, 0, "0", 0, maxdisplayorder); #endregion } ForumCreateResponse fcr = new ForumCreateResponse(); fcr.Fid = fid; fcr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Urls.ShowForumAspxRewrite(fid, 1, forum.RewriteName); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(fcr) : SerializationHelper.Serialize(fcr); return true; }
public override bool Run(CommandParameter commandParam, ref string result) { int uid = commandParam.GetIntParam("uid"); //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } if (commandParam.LocalUid != uid) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("uid,original_password,new_password,confirm_new_password")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string originalPassword = commandParam.GetDNTParam("original_password").ToString(); string newPassword = commandParam.GetDNTParam("new_password").ToString(); string confirmNewPassword = commandParam.GetDNTParam("confirm_new_password").ToString(); if (newPassword != confirmNewPassword) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } bool isMD5Passwd = commandParam.GetDNTParam("password_format") != null && commandParam.GetDNTParam("password_format").ToString().ToLower() == "md5"; ShortUserInfo user = Discuz.Forum.Users.GetShortUserInfo(uid); if (!isMD5Passwd) { originalPassword = Utils.MD5(originalPassword); } if (user.Password != originalPassword) { result = Util.CreateErrorMessage(ErrorType.API_EC_ORI_PASSWORD_EQUAL_FALSE, commandParam.ParamList); return(false); } bool updateSuccess = Discuz.Forum.Users.UpdateUserPassword(uid, newPassword, !isMD5Passwd); if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", updateSuccess.ToString().ToLower()); } else { ChangePasswordResponse cpr = new ChangePasswordResponse(); cpr.Successfull = updateSuccess ? 1 : 0; result = SerializationHelper.Serialize(cpr); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { ShortUserInfo localUserInfo = null; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } localUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (localUserInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("uids,fields")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string[] uIds = commandParam.GetDNTParam("uids").ToString().Split(','); //单次最多接受查询100个用户 if (!Utils.IsNumericArray(uIds) || Utils.StrToInt(uIds[0], -1) < 1 || uIds.Length > 100) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } List<User> userList = new List<User>(); UserInfo userInfo; for (int i = 0; i < uIds.Length; i++) { int userid = Utils.StrToInt(uIds[i], -1); if (userid < 1) continue; userInfo = Discuz.Forum.Users.GetUserInfo(userid); if (userInfo == null) continue; bool loadAuthAttr = true; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) loadAuthAttr = userInfo.Uid == localUserInfo.Uid || localUserInfo.Adminid == 1; userList.Add(UserCommandUtils.LoadSingleUser(userInfo, commandParam.GetDNTParam("fields").ToString(), loadAuthAttr)); } UserInfoResponse uir = new UserInfoResponse(); uir.user_array = userList.ToArray(); uir.List = true; if (commandParam.Format == FormatType.JSON) { result = Util.RemoveJsonNull(JavaScriptConvert.SerializeObject(userList.ToArray())); } else { //如果userList长度不大于1,则移除空节点会导致客户端反序列化错误 //result = userList.Count > 1 ? Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()) : //SerializationHelper.Serialize(uir); result = Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { ShortUserInfo localUserInfo = null; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } localUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (localUserInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("email,fields")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } List <UserInfo> userList = new List <UserInfo>(); List <User> userListResult = new List <User>(); userList = Discuz.Forum.Users.GetUserListByEmail(commandParam.GetDNTParam("email").ToString().Trim()); string fields = commandParam.GetDNTParam("fields").ToString(); foreach (UserInfo userInfo in userList) { bool loadAuthAttr = true; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { loadAuthAttr = userInfo.Uid == localUserInfo.Uid || localUserInfo.Adminid == 1; } userListResult.Add(UserCommandUtils.LoadSingleUser(userInfo, fields, loadAuthAttr)); } UserInfoResponse uir = new UserInfoResponse(); uir.user_array = userListResult.ToArray(); uir.List = true; if (commandParam.Format == FormatType.JSON) { result = Util.RemoveJsonNull(JavaScriptConvert.SerializeObject(userListResult.ToArray())); } else { //如果userList长度不大于1,则移除空节点会导致客户端反序列化错误 //result = userListResult.Count > 1 ? Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()) : //SerializationHelper.Serialize(uir); result = Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("user_name")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int uid = Users.GetUserId(commandParam.GetDNTParam("user_name").ToString()); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", uid); else { GetIDResponse gir = new GetIDResponse(); gir.UId = uid; result = SerializationHelper.Serialize(gir); } return true; }
/* * 每个用户UID 30秒内只能调用一次该接口 */ public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } if (!commandParam.CheckRequiredParams("subject,message,to_ids")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string ids = commandParam.GetDNTParam("to_ids").ToString(); if (!Utils.IsNumericList(ids)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string[] idArray = ids.Split(','); if (idArray.Length > 10) { result = Util.CreateErrorMessage(ErrorType.API_EC_PM_TOID_OVERFLOW, commandParam.ParamList); return(false); } //桌面应用程序用户强制使用session_info.uid int fromId = commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP ? commandParam.LocalUid : commandParam.GetIntParam("from_id", commandParam.LocalUid); ShortUserInfo fromUserInfo = Discuz.Forum.Users.GetShortUserInfo(fromId); if (fromUserInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_PM_FROMID_NOT_EXIST, commandParam.ParamList); return(false); } //如果发送用户不是管理员,且在30秒内调用了该接口 if (fromUserInfo.Adminid != 1 && !CommandCacheQueue <SendMessageItem> .EnQueue(new SendMessageItem(fromUserInfo.Uid, DateTime.Now.Ticks))) { result = Util.CreateErrorMessage(ErrorType.API_EC_PM_VISIT_TOOFAST, commandParam.ParamList); return(false); } string message = UBB.ParseUrl(Utils.EncodeHtml(commandParam.GetDNTParam("message").ToString())); string successfulIds = string.Empty; foreach (string id in ids.Split(',')) { int toUid = TypeConverter.StrToInt(id); if (toUid < 1 || toUid == fromId) { continue; } ShortUserInfo toUserInfo = Discuz.Forum.Users.GetShortUserInfo(toUid); if (toUserInfo == null) { continue; } PrivateMessageInfo pm = new PrivateMessageInfo(); pm.Folder = 0; pm.Message = message; pm.Msgfrom = fromUserInfo.Username; pm.Msgfromid = fromId; pm.Msgto = toUserInfo.Username; pm.Msgtoid = TypeConverter.StrToInt(id); pm.New = 1; pm.Postdatetime = Utils.GetDateTime(); pm.Subject = commandParam.GetDNTParam("subject").ToString(); successfulIds += (PrivateMessages.CreatePrivateMessage(pm, 0) > 0) ? (id + ",") : ""; } successfulIds = successfulIds.Length > 0 ? successfulIds.Remove(successfulIds.Length - 1) : successfulIds; if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", successfulIds); } else { MessageSendResponse nsr = new MessageSendResponse(); nsr.Result = successfulIds; result = SerializationHelper.Serialize(nsr); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { ShortUserInfo localUserInfo = null; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } localUserInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (localUserInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_USER_NOT_EXIST, commandParam.ParamList); return false; } } if (!commandParam.CheckRequiredParams("email,fields")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } List<UserInfo> userList = new List<UserInfo>(); List<User> userListResult = new List<User>(); userList = Discuz.Forum.Users.GetUserListByEmail(commandParam.GetDNTParam("email").ToString().Trim()); string fields = commandParam.GetDNTParam("fields").ToString(); foreach (UserInfo userInfo in userList) { bool loadAuthAttr = true; if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) loadAuthAttr = userInfo.Uid == localUserInfo.Uid || localUserInfo.Adminid == 1; userListResult.Add(UserCommandUtils.LoadSingleUser(userInfo, fields, loadAuthAttr)); } UserInfoResponse uir = new UserInfoResponse(); uir.user_array = userListResult.ToArray(); uir.List = true; if (commandParam.Format == FormatType.JSON) { result = Util.RemoveJsonNull(JavaScriptConvert.SerializeObject(userListResult.ToArray())); } else { //如果userList长度不大于1,则移除空节点会导致客户端反序列化错误 //result = userListResult.Count > 1 ? Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()) : //SerializationHelper.Serialize(uir); result = Util.RemoveEmptyNodes(SerializationHelper.Serialize(uir), commandParam.GetDNTParam("fields").ToString()); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { if (!commandParam.CheckRequiredParams("post_ids,tid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string successfulIds = string.Empty; int tid = commandParam.GetIntParam("tid"); //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid); TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid); if (!Discuz.Forum.Moderators.IsModer(userInfo.Adminid, commandParam.LocalUid, topicInfo.Fid)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } int i = 0; string postTableId = Discuz.Forum.Posts.GetPostTableId(tid); foreach (string s in commandParam.GetDNTParam("post_ids").ToString().Split(',')) { int pid = TypeConverter.StrToInt(s); if (pid < 1) continue; if (Discuz.Forum.Posts.DeletePost(postTableId, pid, false, true) > 0) successfulIds += (pid + ","); if (++i >= 20) break; } if (successfulIds.Length > 0) successfulIds = successfulIds.Remove(successfulIds.Length - 1); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", successfulIds); else { TopicDeleteRepliesResponse tdrr = new TopicDeleteRepliesResponse(); tdrr.Result = successfulIds; result = SerializationHelper.Serialize(tdrr); } return true; }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } //如果当前用户不是管理员 if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("notification")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } //给当前登录用户发送通知可以将to_ids设置为空 if (commandParam.LocalUid < 1 && (!commandParam.CheckRequiredParams("to_ids") || !Utils.IsNumericList(commandParam.GetDNTParam("to_ids").ToString()))) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } string ids = commandParam.GetDNTParam("to_ids").ToString(); string notification = commandParam.GetDNTParam("notification").ToString(); string[] to_ids; if (ids == string.Empty) { to_ids = new string[1]; to_ids[0] = commandParam.LocalUid.ToString(); } else { to_ids = commandParam.GetDNTParam("to_ids").ToString().Split(','); } string successfulIds = string.Empty; ShortUserInfo shortUserInfo = null; if (commandParam.LocalUid > 0) { shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid); } foreach (string id in to_ids) { if (Utils.StrToInt(id, 0) < 1) { continue; } NoticeInfo noticeinfo = new NoticeInfo(); noticeinfo.Uid = Utils.StrToInt(id, 0); noticeinfo.New = 1; noticeinfo.Postdatetime = Utils.GetDateTime(); //如果应用程序没有指定来源id,则会将当前应用程序id的hash值作为来源ID,若不指定来源id,用户的通知列表中只存在一条最新的应用程序通知 noticeinfo.Fromid = commandParam.GetIntParam("from_id", Utils.BKDEHash(commandParam.AppInfo.APIKey, 113)); //如果应用程序指定了来源id,则通知类型为“应用程序自定义通知”,否则是“应用程序通知” noticeinfo.Type = commandParam.CheckRequiredParams("from_id") ? NoticeType.ApplicationCustomNotice : NoticeType.ApplicationNotice; if (commandParam.LocalUid > 0) { noticeinfo.Poster = shortUserInfo == null ? "" : shortUserInfo.Username; noticeinfo.Posterid = commandParam.LocalUid; } else { noticeinfo.Poster = ""; noticeinfo.Posterid = 0; } noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换 if (Notices.CreateNoticeInfo(noticeinfo) > 0) { successfulIds += (id + ","); } } if (successfulIds.Length > 0) { successfulIds = successfulIds.Remove(successfulIds.Length - 1); } if (commandParam.Format == FormatType.JSON) { result = string.Format("\"{0}\"", successfulIds); } else { NotificationSendResponse nsr = new NotificationSendResponse(); nsr.Result = successfulIds; result = SerializationHelper.Serialize(nsr); } return(true); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 //if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) //{ // if (commandParam.LocalUid < 1) // { // result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); // return false; // } //} if (!commandParam.CheckRequiredParams("fid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } int fid = Utils.StrToInt(commandParam.GetDNTParam("fid"), 0); if (fid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return(false); } ForumGetResponse fgr = new ForumGetResponse(); fgr.Fid = fid; fgr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Urls.ShowForumAspxRewrite(fid, 1, forumInfo.Rewritename); fgr.CurTopics = forumInfo.CurrentTopics; fgr.Description = forumInfo.Description; fgr.Icon = forumInfo.Icon; fgr.LastPost = forumInfo.Lastpost; fgr.LastPoster = forumInfo.Lastposter.Trim(); fgr.LastPosterId = forumInfo.Lastposterid; fgr.LastTid = forumInfo.Lasttid; fgr.LastTitle = forumInfo.Lasttitle.Trim(); fgr.Moderators = forumInfo.Moderators; fgr.Name = forumInfo.Name; fgr.ParentId = forumInfo.Parentid; fgr.ParentIdList = forumInfo.Parentidlist.Trim(); fgr.PathList = forumInfo.Pathlist.Trim(); fgr.Posts = forumInfo.Posts; fgr.Rules = forumInfo.Rules; fgr.Status = forumInfo.Status; fgr.SubForumCount = forumInfo.Subforumcount; fgr.TodayPosts = forumInfo.Todayposts; fgr.Topics = forumInfo.Topics; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(fgr) : SerializationHelper.Serialize(fgr); return(true); }