コード例 #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("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);
        }
コード例 #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("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);
        }
コード例 #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_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);
        }