public async Task <IActionResult> CreateCredential([Bind("ProjectId,Login,Notes,Password,Title")] CreateCredentialViewModel createViewModel) { if (createViewModel.ProjectId < 0) { return(NotFound()); } if (ModelState.IsValid == true) { try { var asset = new Credential(); asset.Title = createViewModel.Title; asset.Notes = createViewModel.Notes; asset.Login = createViewModel.Login; asset.Password = createViewModel.Password; // get IP string accessIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString(); await _assetService.AddAssetToProjectAsync(createViewModel.ProjectId, asset, accessIpAddress); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(Details), new { id = createViewModel.ProjectId })); } return(RedirectToAction(nameof(Index))); }
public static CreateCredentialViewModel GetCredentialViewModel(Project project) { var viewModel = new CreateCredentialViewModel(); viewModel.ProjectId = project.Id; viewModel.ProjectTitle = project.Title; return(viewModel); }
public ActionResult CreateCredential() { if (Username == null) { return(RedirectToAction("Login")); } CreateCredentialViewModel model = new CreateCredentialViewModel(); return(View(model)); }
public async Task <IActionResult> Create(CreateCredentialViewModel model, string action) { switch (action) { case "create" when ModelState.IsValid: { var context = new ApplicationContext(); var user = await _userManager.GetUserAsync(User); var credential = new Credential { Source = model.Source, Login = model.Login, Password = model.Password, UserId = user.Id }; context.Credentials.Add(credential); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } case "create": return(View(model)); case "generate": { if (model.Source != null) { HttpContext.Response.Cookies.Append("source", model.Source); } if (model.Login != null) { HttpContext.Response.Cookies.Append("login", model.Login); } return(RedirectToAction("Index", "Generator")); } default: return(Content("Неопознанное действие")); } }
public IActionResult SaveFromGenerator(string generatedPassword) { var model = new CreateCredentialViewModel { Password = generatedPassword }; if (HttpContext.Request.Cookies.ContainsKey("source")) { model.Source = HttpContext.Request.Cookies["source"]; HttpContext.Response.Cookies.Delete("source"); } if (HttpContext.Request.Cookies.ContainsKey("login")) { model.Login = HttpContext.Request.Cookies["login"]; HttpContext.Response.Cookies.Delete("login"); } return(View("Create", model)); }
public ActionResult CreateCredential(CreateCredentialFormModel Form) { CreateCredentialViewModel model = new CreateCredentialViewModel(); model.Form = Form; Form.type = "NatIDNumCredentialPersonV1"; if (!ModelState.IsValid) { return(View(model)); } string user = UserDids.FirstOrDefault(x => x.Value == HolderDid).Key; BuildUnsignedVCRequest requestVC = new BuildUnsignedVCRequest { data = Form, holderDid = HolderDid, type = "NatIDNumCredentialPersonV1" }; var json = JsonConvert.SerializeObject(requestVC); var data = new StringContent(json, Encoding.UTF8, "application/json"); var url = AffinidyURLIssuer + "/vc/build-unsigned"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Api-Key", HashAffinidy); var response = client.PostAsync(url, data).Result; string result = response.Content.ReadAsStringAsync().Result; var respuesta = JsonConvert.DeserializeObject <BuildUnsignedVCResponse>(result); if (UnsignedCredentials.ContainsKey(user)) { UnsignedCredentials[user].Add(respuesta); } else { UnsignedCredentials.Add(user, new List <BuildUnsignedVCResponse>() { respuesta }); } ViewBag.Message = "Successful signup."; return(RedirectToAction("CredentialCreated")); } }