Exemple #1
0
        }// End Constructor

        // Method - Store Credentials
        private void StorePW(object sender, RoutedEventArgs e)
        {
            // Tenant = null => return
            if (string.IsNullOrEmpty(Tenant.Text))
            {
                MessageBox.Show("Please provide a Tenant", "My app", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            // We create the PasswordRepository
            var repo = new PasswordRepository();
            // Build the adminUrl from userInput
            string adminUrl = "https://" + Tenant.Text + "-admin.sharepoint.com";

            // If Login Sceanrio => Login
            if (string.IsNullOrEmpty(TBUN.Text))
            {
                // Get the credentials from Credential Manager
                CredentialManagement.Credential cred = repo.GetCred(adminUrl);
                if (cred.Exists())
                {
                    this.Hide();
                    new Sitesmanagement(adminUrl).Show();
                    return;
                }
                else
                {
                    MessageBox.Show("Please Register this Tenant");
                    return;
                }
            }

            // If Register Screnario => Register & Login
            if ((!string.IsNullOrEmpty(TBUN.Text)) && (PBPW.SecurePassword != null))
            {
                try
                {
                    repo.SaveCred(PBPW.SecurePassword, TBUN.Text, adminUrl);
                    this.Hide();
                    new Sitesmanagement(adminUrl).Show();
                    return;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "My app", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            //else we ask for UserName and PassWord
            MessageBox.Show("Please provide a UserName and PassWord");
        }// End Method
Exemple #2
0
        private void StorePW(object sender, RoutedEventArgs e)
        {
            var repo       = new PasswordRepository();
            var tryConnect = new SPOtLightMenu();

            if (!string.IsNullOrEmpty(TBUN.Text))
            {
                repo.SaveCred(PBPW.SecurePassword, TBUN.Text);
                this.Hide();
            }
            CredentialManagement.Credential cred = repo.GetCred();
            if (cred.Exists())
            {
                this.Hide();
                new Sitesmanagement().Show();
            }
        }
 /// <summary>
 /// Restores credential from Windows Credential Manager, and stores in <see cref="Credential"/>
 /// </summary>
 /// <returns>Credential from Credential Manager</returns>
 public NetworkCredential GetCredentials()
 {
     using (var credentialManager = new CredentialManagement.Credential())
     {
         var credential = new NetworkCredential();
         credentialManager.Target = _credentialsName;
         credentialManager.Load();
         if (credentialManager.Exists())
         {
             credential.UserName = credentialManager.Username;
             // Username was set with domain, for example "DOMAIN\Username"
             if (credential.UserName.Contains("\\"))
             {
                 // Domain will be set to a string before backslash.
                 credential.Domain = credential.UserName.Split('\\')[0];
                 // Username will be set to a string after backslash.
                 credential.UserName = credential.UserName.Split('\\')[1];
             }
             credential.Password = credentialManager.Password;
         }
         return(credential);
     }
 }
Exemple #4
0
        private bool EnsureGitHubClient()
        {
            if (gitHubClient == null)
            {
                // Load git credentials from Windows credential management store (vault)
                var credential = new CredentialManagement.Credential {
                    Target = "git:https://github.com"
                };
                if (!credential.Exists())
                {
                    MessageBox.Show(Resources.Error_CredentialNotFound.FormatWith(credential.Target));
                    return(false);
                }
                if (!credential.Load())
                {
                    MessageBox.Show(Resources.Error_CredentialLoadFailed.FormatWith(credential.Target));
                    return(false);
                }

                gitHubClient             = new GitHubClient(new ProductHeaderValue(System.Windows.Forms.Application.ProductName));
                gitHubClient.Credentials = new Credentials(credential.Username, credential.Password);

                try
                {
                    var repo = gitHubClient.Repository.Get(textBoxOwner.Text, textBoxRepository.Text).Result;
                    repositoryId = repo.Id;

                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            return(false);
        }