Example #1
0
        /// <summary>
        /// 保存密码
        /// </summary>
        private void SavePassword()
        {
            if (OldPassword != null && NewPassword != null && ConfirmPassword != null)
            {
                string oldPassword     = ClientHelper.Encryption(OldPassword.Trim());
                string newPassword     = ClientHelper.Encryption(NewPassword.Trim());
                string confirmPassword = ClientHelper.Encryption(ConfirmPassword.Trim());
                if (newPassword.Length >= 6 && newPassword.Equals(confirmPassword))
                {
                    if (HomeViewModel.RequestResultAction == null)
                    {
                        HomeViewModel.RequestResultAction = (RequestResult result) =>
                        {
                            switch (result.Success)
                            {
                            case true:
                                EditInfo.EditInfoWindow.Dispatcher.Invoke(() =>
                                {
                                    EditInfo.EditInfoWindow?.Close();
                                });
                                MessageBox.Show("密码保存成功!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                                break;

                            case false:
                                MessageBox.Show("输入的旧密码与原密码不一致!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
                                break;

                            default:
                                MessageBox.Show("密码保存失败!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                                break;
                            }
                        };

                        if (!Config.MiniClient.SendDatabaseRequest(new User()
                        {
                            UserName = _userModel.UserName, Password = oldPassword
                        }, "AlterPassword", newPassword))
                        {
                            HomeViewModel.RequestResultAction = null;
                            MessageBox.Show("保存密码时发生错误!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    return;
                }
                MessageBox.Show("密码不符合要求!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            MessageBox.Show("密码不能为空!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
        }
        public async void ChangePassword()
        {
            var confirm = await Application.Current.MainPage.DisplayAlert(Resx.AppResources.ChangePasswordTitle, Resx.AppResources.ChangePasswordWarning,
                                                                          Resx.AppResources.Yes, Resx.AppResources.Cancel);

            if (confirm)
            {
                var userService = new Services.UserService();
                var result      = await userService.ChangePassword(OldPassword.Trim(), NewPassword.Trim());

                if (result != UsuarioResultEnum.Ok)
                {
                    var toastService = new Services.ToastService();
                    toastService.SendToast(result.GetText());
                }
                else
                {
                    var navigationService = new Services.NavigationService();
                    userService.DoLogout();
                    navigationService.GoToLogin();
                }
            }
        }