Exemplo n.º 1
0
        /// <summary>
        /// 13、 修改密码[PUT]:v1/user/{userId}/account
        /// </summary>
        /// <param name="input"></param>
        /// <param name="errorCode">错误代码</param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool ChangePassword(AntSdkChangePasswordInput input, ref int errorCode, ref string errorMsg)
        {
            var output = new AntSdkBaseOutput();

            return
                (AntSdkHttpCommonMethod(
                     string.Format(AntSdkService.MdAntsdkhttpMethod.ChangePassWord, AntSdkService.AntSdkLoginOutput.userId), input,
                     ref output, ref errorCode, ref errorMsg,
                     RequestMethod.POST));
        }
Exemplo n.º 2
0
        private bool ChangePassword()
        {
            bool changeResult = false;

            try
            {
                var       errCode   = 0;
                string    errMsg    = string.Empty;
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Restart();

                //ChangePasswordInput input = new ChangePasswordInput
                //{
                //    newPwd = NewPassword,
                //    oldPwd = Password,
                //    version = GlobalVariable.Version,
                //    token = AntSdkService.AntSdkLoginOutput.token,
                //    userId = AntSdkService.AntSdkCurrentUserInfo.userId
                //};
                //ChangePasswordOutput output = new ChangePasswordOutput();
                //TODO:AntSdk_Modify
                //DONE:AntSdk_Modify
                AntSdkChangePasswordInput changePasswordInput = new AntSdkChangePasswordInput();
                changePasswordInput.newPassword = NewPassword;
                changePasswordInput.password    = Password;
                var isResult = AntSdkService.AntSdkChangePassword(changePasswordInput, ref errCode, ref errMsg);
                if (isResult)
                {
                    changeResult = true;
                    string             errMessage      = string.Empty;
                    List <AccountInfo> listAccountInfo = new List <AccountInfo>();
                    DataConverter.XmlToEntity(Environment.CurrentDirectory + "/AccountCache.xml", ref listAccountInfo,
                                              ref errMessage);
                    if (listAccountInfo.Any())
                    {
                        if (AntSdkService.AntSdkCurrentUserInfo != null)
                        {
                            AccountInfo info =
                                listAccountInfo.FirstOrDefault(
                                    c => c.ID == AntSdkService.AntSdkCurrentUserInfo.loginName);
                            if (info != null)
                            {
                                info.LastLoginTime = DateTime.Now;
                                info.OnLine        = 0;
                                info.RememberPwd   = false;
                                info.AutoLogin     = false;
                                info.Password      = string.Empty;
                            }
                            DataConverter.EntityToXml <List <AccountInfo> >(
                                System.Environment.CurrentDirectory + "/AccountCache.xml", listAccountInfo,
                                ref errMessage);
                        }
                    }
                }
                //if ((new HttpService()).ChangePassword(input, ref output, ref errMsg))
                //{
                //    changeResult = true;
                //    string errMessage = string.Empty;
                //    List<AccountInfo> listAccountInfo = new List<AccountInfo>();
                //    DataConverter.XmlToEntity(Environment.CurrentDirectory + "/AccountCache.xml", ref listAccountInfo, ref errMessage);
                //    if (listAccountInfo.Any())
                //    {
                //        if (AntSdkService.AntSdkCurrentUserInfo != null)
                //        {
                //            AccountInfo info = listAccountInfo.FirstOrDefault(c => c.ID == AntSdkService.AntSdkCurrentUserInfo.loginName);
                //            if (info != null)
                //            {
                //                info.LastLoginTime = DateTime.Now;
                //                info.OnLine = 0;
                //                info.RememberPwd = false;
                //                info.AutoLogin = false;
                //                info.Password = string.Empty;
                //            }
                //            DataConverter.EntityToXml<List<AccountInfo>>(System.Environment.CurrentDirectory + "/AccountCache.xml", listAccountInfo, ref errMessage);
                //        }
                //    }
                //}
                stopWatch.Stop();
                LogHelper.WriteDebug(string.Format("[ChangePassword failed ({0}毫秒)]", stopWatch.Elapsed.TotalMilliseconds));
                ErrMsg = errMsg;
            }
            catch (Exception ex)
            {
                changeResult = false;
                ErrMsg       = $"修改密码时发生异常:{ex.Message}";
                LogHelper.WriteError(ErrMsg);
            }
            return(changeResult);
        }