Ejemplo n.º 1
0
        /// <summary>
        /// 根据用户名获得用户ID
        /// </summary>
        /// <returns></returns>
        public string GetID()
        {
            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 (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return("");
            }

            if (!this.CheckRequiredParams("user_name"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            int uid = Discuz.Forum.Users.GetUserId(GetParam("user_name").ToString());

            if (Format == FormatType.JSON)
            {
                return(string.Format("\"{0}\"", uid));
            }

            GetIDResponse gir = new GetIDResponse();

            gir.UId = uid;

            return(SerializationHelper.Serialize(gir));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据用户名获得用户ID
        /// </summary>
        /// <returns></returns>
        public string GetID()
        {
            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 (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return "";
            }

            if (!this.CheckRequiredParams("user_name"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            int uid = Discuz.Forum.Users.GetUserId(GetParam("user_name").ToString());
            if (Format == FormatType.JSON)
                return string.Format("\"{0}\"", uid);

            GetIDResponse gir = new GetIDResponse();
            gir.UId = uid;

            return SerializationHelper.Serialize(gir);
        }
Ejemplo n.º 3
0
        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;
        }