public ScopeEditViewModel() { NewScope = new ScopeItemViewModel(); NewScopeClaim = new NewScopeClaimViewModel(); NewScopeSecret = new NewScopeSecretViewModel(); }
public async Task<IActionResult> AddScopeSecret(NewScopeSecretViewModel scopeModel) { if (!ModelState.IsValid) { return RedirectToAction("EditScope", new { siteId = scopeModel.SiteId, scopeName = scopeModel.ScopeName }); } Guid siteId = siteManager.CurrentSite.Id; if (!string.IsNullOrEmpty(scopeModel.SiteId) && scopeModel.SiteId.Length == 36) { siteId = new Guid(scopeModel.SiteId); } var selectedSite = await siteManager.GetSiteForDataOperations(siteId); var scope = await scopesManager.FetchScope(selectedSite.Id.ToString(), scopeModel.ScopeName); if (scope == null) { this.AlertDanger(sr["Invalid request, scope not found."], true); return RedirectToAction("Index"); } var secret = new Secret(scopeModel.Value, scopeModel.Description, scopeModel.Expiration); secret.Type = scopeModel.Type; if (scope.ScopeSecrets.Contains(secret)) { this.AlertDanger(sr["Scope already has a secret with that value."], true); return RedirectToAction("EditScope", new { siteId = selectedSite.Id.ToString(), scopeName = scopeModel.ScopeName }); } scope.ScopeSecrets.Add(secret); await scopesManager.UpdateScope(selectedSite.Id.ToString(), scope); this.AlertSuccess(sr["The Secret was successfully added."], true); return RedirectToAction("EditScope", new { siteId = selectedSite.Id.ToString(), scopeName = scopeModel.ScopeName }); }