Ejemplo n.º 1
0
        /// <summary>
        /// 删除指定主题
        /// </summary>
        /// <returns></returns>
        public string Delete()
        {
            if (Signature != GetParam("sig").ToString())
            {
                ErrorCode = (int)ErrorType.API_EC_SIGNATURE;
                return "";
            }

            //如果是桌面程序则需要验证用户身份
            if (this.App.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (Uid < 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_SESSIONKEY;
                    return "";
                }
            }

            //if (Uid < 1)
            //{
            //    ErrorCode = (int)ErrorType.API_EC_SESSIONKEY;
            //    return "";
            //}

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return string.Empty;
            }

            if (!CheckRequiredParams("topic_ids"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return string.Empty;
            }

            string topicIds = GetParam("topic_ids").ToString();
            if (!Utils.IsNumericList(topicIds))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return string.Empty;
            }

            if (topicIds.Split(',').Length > 20)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return string.Empty;
            }
            int forumId = TypeConverter.ObjectToInt(GetParam("fid"));

            if (this.App.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (!CheckRequiredParams("fid"))
                {
                    ErrorCode = (int)ErrorType.API_EC_PARAM;
                    return string.Empty;
                }
                ShortUserInfo user = Discuz.Forum.Users.GetShortUserInfo(Uid);
                if (user == null || !Moderators.IsModer(user.Adminid, Uid, forumId))
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return string.Empty;
                }

                if (!Discuz.Forum.Topics.InSameForum(topicIds, forumId))
                {
                    ErrorCode = (int)ErrorType.API_EC_PARAM;
                    return string.Empty;
                }
            }

            bool result = Discuz.Forum.TopicAdmins.DeleteTopics(topicIds, false) > 0;

            TopicDeleteResponse tdr = new TopicDeleteResponse();
            tdr.Successfull = result ? 1 : 0;
            if (Format == FormatType.JSON)
                return string.Format("\"{0}\"", result.ToString().ToLower());

            return SerializationHelper.Serialize(tdr);

        }
Ejemplo n.º 2
0
        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;
        }