//вход по кнопке и переход на страницу вашей музыки private void enter_Click(object sender, RoutedEventArgs e) { if (Tlogin.Text != "") { if (Tpassword.Password != "") { //в main объект статический (иначе не работает, не понял по чему), обращаться из вне main //т.к. метод возвращает true/false, надо придумать, как сделать переход с login на list if (MainWindow.vk1.Auth(new string(Tlogin.Text), new string(Tpassword.Password)) != true) { MessageBox.Show("Неправильный логин или пароль."); return; } // /*MessageBox.Show(LoginFile.ReadAuto());*/ //MainWindow.vk1.getAud(); if (LoginFile.ReadAuto() == true) { LoginFile.RecLog(new string(Tlogin.Text), new string(Tpassword.Password)); } } } NavigationService service = NavigationService.GetNavigationService(this); service.Navigate(App.l1); App.l1.MesAutUser(); App.l1.LoadAudioList(MainWindow.vk1.getIdThisUser()); }
//----------------------------------------------------------------- // Static members /// <summary> /// Reads a login file. Note that this does not throw exceptions and instead deletes /// the existing file and returns <c>null</c>. /// </summary> /// <param name="path">Path to the file.</param> /// <returns>The <see cref="LoginFile"/> or <c>null</c> when it is missing or invalid.</returns> public static LoginFile Read(string path) { Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(path), nameof(path)); var loginFile = new LoginFile() { Path = path }; try { var loginData = NeonHelper.JsonDeserialize <LoginData>(File.ReadAllText(path)); loginFile.Sha256 = System.IO.Path.GetFileNameWithoutExtension(path); loginFile.Location = loginData.Location; loginFile.Username = loginData.Username; loginFile.UpdatedUtc = loginData.UpdatedUtc; } catch { NeonHelper.DeleteFile(path); return(null); } return(loginFile); }
//авто вход public void AutoEnter() { if (LoginFile.ReadAuto()) { Tlogin.Text = LoginFile.ReadLog()[0]; Tpassword.Password = LoginFile.ReadLog()[1]; //enter_Click(new Object(),new RoutedEventArgs()); из-за этого выкидывает ошибку при переходе на list } }
//выход из под своей учётки private void exit_Click(object sender, RoutedEventArgs e) { LoginFile.RecAuto(false); LoginFile.DelLog(); NavigationService service = NavigationService.GetNavigationService(this); MessageBox.Show(MainWindow.vk1.LogOut()); service.Navigate(App.log1); }
/// <summary> /// Creates a new login file instance with parameters passed, but does not persist /// the file. Use <see cref="Write()"/> to do this. /// </summary> /// <param name="loginFolder">Specifies the path to the login folder.</param> /// <param name="registryUri">Specifies the upstream registry URI.</param> /// <param name="userName">Specifies the user name used to login.</param> /// <param name="password">Specifies the password.</param> /// <returns>The <see cref="LoginFile"/>.</returns> public static LoginFile Create(string loginFolder, string registryUri, string userName, string password) { Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(loginFolder), nameof(loginFolder)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(registryUri), nameof(registryUri)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(userName), nameof(userName)); Covenant.Requires <ArgumentNullException>(password != null, nameof(password)); var loginFile = new LoginFile() { Location = registryUri, Username = userName, Password = password, Sha256 = CryptoHelper.ComputeSHA256String($"{registryUri},{userName},{password}") }; loginFile.Path = System.IO.Path.Combine(loginFolder, $"{loginFile.Sha256}.login"); return(loginFile); }
private void Login_Click(object sender, RoutedEventArgs e) { login = new LoginFile(); un = txtUsername.Text; pw = txtPassword.Password.ToString(); User u = new User(un, pw); if (login.AuthenticateLogin(u)) { Current = u; Current.DisplayName = login.Find(u); var win = new MainWindow(Current); win.Show(); this.Close(); } else { LoginErrMessage.Text = "Incorrect Username and/or Password, Please Try Again."; } }
private void Register_Click(object sender, RoutedEventArgs e) { login = new LoginFile(); dn = txtDisplayName.Text; un = txtUsername.Text; pw = txtPassword.Password.ToString(); if (un != "" && pw != "" && pw.Length >= 8) { login.UpdateFile(new User(un, pw, dn)); var win = new LoginScreen(); win.Show(); this.Close(); } else if (un == "" || pw == "") { RegErrMessage.Text = "Username and/or Password cannot be empty."; } else { RegErrMessage.Text = "Password must be be at least 8 characters."; } }
//Раззпомнить данные для входа private void checkBox_Unchecked(object sender, RoutedEventArgs e) { LoginFile.RecAuto(false); }
/// <summary> /// Rebuilds the host node's <b>/etc/containers/registries.conf.d/00-neon-cluster.conf</b> file, /// using the container registries passed, signals CRI-O to reload any changes and also manages /// container registry logins. /// </summary> private async Task UpdateContainerRegistriesAsync() { var registries = (await k8s.ListClusterCustomObjectAsync <V1NeonContainerRegistry>()).Items; // NOTE: Here's the documentation for the config file we're generating: // // https://github.com/containers/image/blob/main/docs/containers-registries.conf.5.md // var sbRegistryConfig = new StringBuilder(); var sbSearchRegistries = new StringBuilder(); // Configure any unqualified search registries. foreach (var registry in registries .Where(registry => registry.Spec.SearchOrder >= 0) .OrderBy(registry => registry.Spec.SearchOrder)) { sbSearchRegistries.AppendWithSeparator($"\"{registry.Spec.Prefix}\"", ", "); } sbRegistryConfig.Append( $@"unqualified-search-registries = [{sbSearchRegistries}] "); // Configure any container registries including the local cluster. foreach (var registry in registries) { sbRegistryConfig.Append( $@" [[registry]] prefix = ""{registry.Spec.Prefix}"" insecure = {NeonHelper.ToBoolString(registry.Spec.Insecure)} blocked = {NeonHelper.ToBoolString(registry.Spec.Blocked)} "); if (!string.IsNullOrEmpty(registry.Spec.Location)) { sbRegistryConfig.AppendLine($"location = \"{registry.Spec.Location}\""); } } if (NeonHelper.IsLinux) { // Read and parse the current configuration file to create list of the existing // configured upstream registries. var currentConfigText = File.ReadAllText(configMountPath); var currentConfig = Toml.Parse(currentConfigText); var existingLocations = new List <string>(); foreach (var registryTable in currentConfig.Tables.Where(table => table.Name.Key.GetName() == "registry")) { var location = registryTable.Items.SingleOrDefault(key => key.Key.GetName() == "location")?.Value.GetValue(); if (!string.IsNullOrWhiteSpace(location)) { existingLocations.Add(location); } } // Convert the generated config to Linux line endings and then compare the new // config against what's already configured on the host node. We'll rewrite the // host file and then signal CRI-O to reload its config when the files differ. var newConfigText = NeonHelper.ToLinuxLineEndings(sbRegistryConfig.ToString()); if (currentConfigText != newConfigText) { configUpdateCounter.Inc(); File.WriteAllText(configMountPath, newConfigText); (await Node.ExecuteCaptureAsync("pkill", new object[] { "-HUP", "crio" })).EnsureSuccess(); // Wait a few seconds to give CRI-O a chance to reload its config. This will // help mitigate problems when managing logins below due to potential inconsistencies // between CRI-O's currently loaded config and the new config we just saved. await Task.Delay(TimeSpan.FromSeconds(15)); } } //----------------------------------------------------------------- // We need to manage registry logins by logging into new registries, // logging out of deleted registries, relogging in with new credentials, // and periodically logging in with unchanged credentials to ensure that // we're actually logged in. Here's how this works: // // https://github.com/nforgeio/neonKUBE/issues/1591 var retry = new LinearRetryPolicy(e => true, maxAttempts: 5, retryInterval: TimeSpan.FromSeconds(5)); // Construct LoginFile instances for all specified upstream registries // that require credentials and add these to a dictionary keyed by SHA-256. var shaToRequiredLogins = new Dictionary <string, LoginFile>(); foreach (var registry in registries.Where(registry => !string.IsNullOrEmpty(registry.Spec.Username))) { var loginFile = LoginFile.Create(hostContainerRegistriesFolder, registry.Spec.Location, registry.Spec.Username, registry.Spec.Password); shaToRequiredLogins.Add(loginFile.Sha256, loginFile); } // Read all existing login files on the node and add them to a dictionary // mapping their SHA-256s to the file. var shaToExistingLogins = new Dictionary <string, LoginFile>(); foreach (var file in Directory.GetFiles(hostContainerRegistriesFolder, "*.login", SearchOption.TopDirectoryOnly)) { var loginFile = LoginFile.Read(file); if (loginFile != null) { shaToExistingLogins.Add(loginFile.Sha256, loginFile); } } // Look for any existing login files that are not present in the collection of // new logins. These correspond to registries that have been deleted or whose // credentials have changed. We're going to go ahead and log out of the related // registries and then delete these login files (we'll re-login with new // credentials below for the registries that weren't targeted for removal). foreach (var loginFile in shaToExistingLogins.Values .Where(login => !shaToRequiredLogins.ContainsKey(login.Sha256))) { try { await retry.InvokeAsync( async() => { // Note that we're not ensuring success here because we may not be // logged-in which is OK: we don't want to see that error. log.LogInfo($"{podmanPath} logout {loginFile.Location}"); if (NeonHelper.IsLinux) { await Node.ExecuteCaptureAsync(podmanPath, new object[] { "logout", loginFile.Location }); } loginFile.Delete(); }); } catch (Exception e) { loginErrorCounter.Inc(); log.LogError(e); } } // Look for any required logins that don't have an existing login file, // and then login the registry and then create the login file on success. foreach (var loginFile in shaToRequiredLogins.Values .Where(login => !shaToExistingLogins.ContainsKey(login.Sha256))) { try { await retry.InvokeAsync( async() => { log.LogInfo($"{podmanPath} login {loginFile.Location} --username {loginFile.Username} --password REDACTED"); if (NeonHelper.IsLinux) { (await Node.ExecuteCaptureAsync(podmanPath, new object[] { "login", loginFile.Location, "--username", loginFile.Username, "--password", loginFile.Password })).EnsureSuccess(); } }); loginFile.Write(); } catch (Exception e) { loginErrorCounter.Inc(); log.LogError(e); } } //----------------------------------------------------------------- // Finally, we need to force a re-login for any existing logins that haven't // been explicitly logged into for a while. Note that we're always going to // log into the local Harbor registry. foreach (var file in Directory.GetFiles(hostContainerRegistriesFolder, "*.login", SearchOption.TopDirectoryOnly)) { // Read the next existing login file. var loginFile = LoginFile.Read(file); if (loginFile == null) { continue; } // Update the login with the password from the corresponding container registry resource. var registry = registries.FirstOrDefault(registry => registry.Spec.Location == loginFile.Location); if (registry == null) { log.LogWarn($"Cannot locate [{nameof(V1NeonContainerRegistry)}] resource for [location={loginFile.Location}]."); continue; } loginFile.Password = registry.Spec.Password; // Perform the login. var scheduledLoginUtc = loginFile.UpdatedUtc + reloginInterval + NeonHelper.PseudoRandomTimespan(reloginMaxRandomInterval); if (DateTime.UtcNow <= scheduledLoginUtc || loginFile.Location == KubeConst.LocalClusterRegistry) { try { await retry.InvokeAsync( async() => { log.LogInfo($"{podmanPath} login {loginFile.Location} --username {loginFile.Username} --password REDACTED"); if (NeonHelper.IsLinux) { (await Node.ExecuteCaptureAsync(podmanPath, new object[] { "login", loginFile.Location, "--username", loginFile.Username, "--password", loginFile.Password })).EnsureSuccess(); } }); loginFile.Write(); } catch (Exception e) { loginErrorCounter.Inc(); log.LogError(e); } } } }