Пример #1
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);
                }
            }
        }
        public async Task <bool> PasswordAsync(string password)
        {
            if (this.Mode == JryVideoDataSourceProviderManagerMode.Public)
            {
                return(true);
            }

            var pw = await this.GetPasswordAsync();

            if (pw == null)
            {
                pw = new JrySettingItem("password_sha1", password);
                await this.SettingCollection().InsertOneAsync(pw);
            }
            this.isAuthed = password == pw.Value;
            return(this.isAuthed);
        }