Exemplo n.º 1
0
        private async void Save_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var secrets = new string[] { UserID.Text, Secret1.Text, Secret2.Text };

            StoredCredential credential;

            if (Item != null)
            {
                // edit existing
                credential = new StoredCredential
                {
                    StorageKey   = Item.StorageKey,
                    ProviderType = Item.ProviderType,
                    DateCreated  = DateTime.Now,
                    Secret       = Newtonsoft.Json.JsonConvert.SerializeObject(secrets),
                    Title        = CredentialTitle.Text
                };
            }
            else
            {
                //create new
                credential = new Models.Config.StoredCredential
                {
                    Title        = CredentialTitle.Text,
                    ProviderType = "",
                    StorageKey   = Guid.NewGuid().ToString(),
                    Secret       = Newtonsoft.Json.JsonConvert.SerializeObject(secrets)
                };
            }

            var result = await MainViewModel.UpdateCredential(credential);

            this.Close();
        }
Exemplo n.º 2
0
 private void CredentialsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems != null && e.AddedItems.Count > 0)
     {
         _selectedStoredCredential = (Models.Config.StoredCredential)e.AddedItems[0];
     }
     else
     {
         _selectedStoredCredential = null;
     }
 }
Exemplo n.º 3
0
        private async Task <AccountDetails> GetAccountDetailsFromCredential(Models.Config.StoredCredential credential)
        {
            var json = await _credentialsManager.GetUnlockedCredential(credential.StorageKey);

            if (json != null)
            {
                var account = JsonConvert.DeserializeObject <AccountDetails>(json);

                if (account.CertificateAuthorityId == null)
                {
                    account.CertificateAuthorityId = StandardCertAuthorities.LETS_ENCRYPT;
                }

                return(account);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        private async void Save_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            StoredCredential credential;

            Dictionary <String, string> credentialsToStore = new Dictionary <string, string>();

            if (String.IsNullOrEmpty(EditViewModel.Item.Title))
            {
                MessageBox.Show("Stored credentials require a name.");
                return;
            }

            if (!EditViewModel.CredentialSet.Any())
            {
                MessageBox.Show("No credentials selected.");
                return;
            }

            foreach (var c in this.EditViewModel.CredentialSet)
            {
                //store entered value

                if (c.IsRequired && String.IsNullOrEmpty(c.Value))
                {
                    MessageBox.Show($"{c.Name} is a required value");
                    return;
                }

                if (!String.IsNullOrEmpty(c.Value))
                {
                    credentialsToStore.Add(c.Key, c.Value);
                }
            }

            var item = EditViewModel.Item;

            if (item.StorageKey != null)
            {
                // edit existing
                credential = new StoredCredential
                {
                    StorageKey   = item.StorageKey,
                    ProviderType = item.ProviderType,
                    Secret       = Newtonsoft.Json.JsonConvert.SerializeObject(credentialsToStore),
                    Title        = item.Title
                };
            }
            else
            {
                //create new
                credential = new Models.Config.StoredCredential
                {
                    Title        = item.Title,
                    ProviderType = item.ProviderType,
                    StorageKey   = Guid.NewGuid().ToString(),
                    DateCreated  = DateTime.Now,
                    Secret       = Newtonsoft.Json.JsonConvert.SerializeObject(credentialsToStore)
                };
            }

            this.EditViewModel.Item = await MainViewModel.UpdateCredential(credential);

            this.Close();
        }