PasswordEditorWindow.xaml 的交互逻辑
Inheritance: MahApps.Metro.Controls.MetroWindow
Ejemplo n.º 1
0
        private async void ModeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selected = this.ViewModel.SelectedMode;

            if (selected.Value == JryVideoDataSourceProviderManagerMode.Public)
            {
                JryVideoCore.Current.DataAgent.Switch(JryVideoDataSourceProviderManagerMode.Public);
                await this.ViewModel.ReloadIfInitializedAsync();
            }
            else
            {
                var secure = JryVideoCore.Current.DataAgent.SecureDataCenter;

                if (!secure.IsWork)
                {
                    this.ShowJryVideoMessage("info", "current database not support private mode.");
                    this.SwitchPublic();
                    return;
                }

                string password = null;

                if (!await secure.ProviderManager.HasPasswordAsync())
                {
                    var dlg = new PasswordEditorWindow();
                    dlg.MessageTextBlock.Text = "first time you must set a password.";
                    dlg.MessageTextBlock.Visibility = Visibility.Visible;
                    dlg.Owner = this.TryFindParent<Window>();
                    if (dlg.ShowDialog() != true)
                    {
                        this.SwitchPublic();
                        return;
                    }
                    password = dlg.PasswordResult;
                }
                else
                {
                    var pwDlg = new PasswordWindow();
                    pwDlg.Owner = this.TryFindParent<Window>();
                    if (pwDlg.ShowDialog() == true && !pwDlg.PasswordBox.Password.IsNullOrWhiteSpace())
                    {
                        password = pwDlg.PasswordBox.Password;
                    }
                }

                if (!password.IsNullOrWhiteSpace())
                {
                    var hash = JasilyHash.Create(HashType.SHA1).ComputeHashString(password);
                    if (await secure.ProviderManager.PasswordAsync(hash))
                    {
                        JryVideoCore.Current.DataAgent.Switch(JryVideoDataSourceProviderManagerMode.Private);
                        await this.ViewModel.ReloadIfInitializedAsync();
                        return;
                    }
                }

                this.ShowJryVideoMessage("error", "password error.");
                this.SwitchPublic();
            }
        }
Ejemplo n.º 2
0
        private async void ModeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selected = this.ViewModel.SelectedMode;

            if (selected != null)
            {
                if (selected.Source == JryVideoDataSourceProviderManagerMode.Public)
                {
                    JryVideoCore.Current.Switch(JryVideoDataSourceProviderManagerMode.Public);
                    await this.ViewModel.VideosViewModel.RefreshAsync();
                }
                else
                {
                    var pw = await JryVideoCore.Current.SecureDataCenter.ProviderManager.GetSettingSet()
                        .FindAsync("password_sha1");

                    if (pw == null)
                    {
                        var dlg = new PasswordEditorWindow();
                        dlg.MessageTextBlock.Text = "first time you must set a password.";
                        dlg.MessageTextBlock.Visibility = Visibility.Visible;
                        dlg.Owner = this.TryFindParent<Window>();
                        if (dlg.ShowDialog() != true)
                        {
                            this.ViewModel.SelectedMode = this.ViewModel.ModeCollection.First(
                                z => z.Source == JryVideoDataSourceProviderManagerMode.Public);
                            return;
                        }
                        var hash = JasilyHash.Create(HashType.SHA1).ComputeHashString(dlg.PasswordResult);
                        pw = new JrySettingItem("password_sha1", hash);
                        await JryVideoCore.Current.SecureDataCenter.ProviderManager.GetSettingSet().InsertAsync(pw);
                    }

                    var pwDlg = new PasswordWindow();
                    pwDlg.Owner = this.TryFindParent<Window>();
                    if (pwDlg.ShowDialog() == true)
                    {
                        if (pwDlg.PasswordBox.Password.IsNullOrWhiteSpace() ||
                            JasilyHash.Create(HashType.SHA1).ComputeHashString(pwDlg.PasswordBox.Password) != pw.Value)
                        {
                            this.ShowJryVideoMessage("error", "password error.");
                        }
                        else
                        {
                            JryVideoCore.Current.Switch(JryVideoDataSourceProviderManagerMode.Private);
                            await this.ViewModel.VideosViewModel.RefreshAsync();
                            return;
                        }
                    }

                    this.ViewModel.SelectedMode = this.ViewModel.ModeCollection.First(
                        z => z.Source == JryVideoDataSourceProviderManagerMode.Public);
                }
            }
        }