Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }