/// <summary> /// 设置用户资料 /// </summary> /// <returns></returns> public string SetInfo() { 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 ""; } if (!this.CheckRequiredParams("uid,user_info")) { ErrorCode =(int)ErrorType.API_EC_PARAM; return ""; } int uid = Utils.StrToInt(GetParam("uid").ToString(),0); if (uid <= 0) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } UserForEditing ufe; try { ufe = JavaScriptConvert.DeserializeObject<UserForEditing>(GetParam("user_info").ToString()); } catch { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } UserInfo userinfo = Discuz.Forum.Users.GetUserInfo(uid); if (!string.IsNullOrEmpty(ufe.Password)) { userinfo.Password = ufe.Password; } if (ufe.Bio != null) { userinfo.Bio = ufe.Bio; } if (ufe.Birthday != null) { userinfo.Bday = ufe.Birthday; } if (!string.IsNullOrEmpty(ufe.Email) && userinfo.Email != ufe.Email && CheckEmail(ufe.Email)) { userinfo.Email = ufe.Email; } 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 (ufe.Gender != null) { userinfo.Gender = Utils.StrToInt(ufe.Gender, 0); } if (ufe.Icq != null) { userinfo.Icq = ufe.Icq; } if (ufe.IdCard != null) { userinfo.Idcard = ufe.IdCard; } if (ufe.Location != null) { userinfo.Location = ufe.Location; } if (ufe.Mobile != null) { userinfo.Mobile = ufe.Mobile; } if (ufe.Msn != null) { userinfo.Msn = ufe.Msn; } if (ufe.NickName != null) { userinfo.Nickname = ufe.NickName; } if (ufe.Phone != null) { userinfo.Phone = ufe.Phone; } if (ufe.Qq != null) { userinfo.Qq = ufe.Qq; } if (ufe.RealName != null) { userinfo.Realname = ufe.RealName; } if (ufe.Skype != null) { userinfo.Skype = ufe.Skype; } if (!string.IsNullOrEmpty(ufe.SpaceId)) { userinfo.Spaceid = Utils.StrToInt(ufe.SpaceId,0); } if (ufe.WebSite != null) { userinfo.Website = ufe.WebSite; } if (ufe.Yahoo != null) { userinfo.Yahoo = ufe.Yahoo; } try { //Discuz.Forum.Users.UpdateUserProfile(userinfo); Discuz.Forum.Users.UpdateUser(userinfo); } catch { ErrorCode = (int)ErrorType.API_EC_UNKNOWN; return "0"; } if (Format == FormatType.JSON) { return "true"; } SetInfoResponse sir = new SetInfoResponse(); sir.Successfull = 1; return SerializationHelper.Serialize(sir); }
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; }
/// <summary> /// 设置用户资料 /// </summary> /// <returns></returns> public string SetInfo() { 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("uid,user_info")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } int uid = Utils.StrToInt(GetParam("uid").ToString(), 0); if (uid <= 0) { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } UserForEditing ufe; try { ufe = JavaScriptConvert.DeserializeObject <UserForEditing>(GetParam("user_info").ToString()); } catch { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } UserInfo userinfo = Discuz.Forum.Users.GetUserInfo(uid); if (!string.IsNullOrEmpty(ufe.Password)) { userinfo.Password = ufe.Password; } if (ufe.Bio != null) { userinfo.Bio = ufe.Bio; } if (ufe.Birthday != null) { userinfo.Bday = ufe.Birthday; } if (!string.IsNullOrEmpty(ufe.Email) && userinfo.Email != ufe.Email && CheckEmail(ufe.Email)) { userinfo.Email = ufe.Email; } 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 (ufe.Gender != null) { userinfo.Gender = Utils.StrToInt(ufe.Gender, 0); } if (ufe.Icq != null) { userinfo.Icq = ufe.Icq; } if (ufe.IdCard != null) { userinfo.Idcard = ufe.IdCard; } if (ufe.Location != null) { userinfo.Location = ufe.Location; } if (ufe.Mobile != null) { userinfo.Mobile = ufe.Mobile; } if (ufe.Msn != null) { userinfo.Msn = ufe.Msn; } if (ufe.NickName != null) { userinfo.Nickname = ufe.NickName; } if (ufe.Phone != null) { userinfo.Phone = ufe.Phone; } if (ufe.Qq != null) { userinfo.Qq = ufe.Qq; } if (ufe.RealName != null) { userinfo.Realname = ufe.RealName; } if (ufe.Skype != null) { userinfo.Skype = ufe.Skype; } if (!string.IsNullOrEmpty(ufe.SpaceId)) { userinfo.Spaceid = Utils.StrToInt(ufe.SpaceId, 0); } if (ufe.WebSite != null) { userinfo.Website = ufe.WebSite; } if (ufe.Yahoo != null) { userinfo.Yahoo = ufe.Yahoo; } try { Discuz.Forum.Users.UpdateUser(userinfo); } catch { ErrorCode = (int)ErrorType.API_EC_UNKNOWN; return("0"); } if (Format == FormatType.JSON) { return("true"); } SetInfoResponse sir = new SetInfoResponse(); sir.Successfull = 1; return(SerializationHelper.Serialize(sir)); }
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); }