public ActionResult Settings() { int id = WebSecurity.GetUserId(WebSecurity.CurrentUserName); UserProfile profile = _context.UserProfiles.First(x => x.UserId == id); SettingsViewModel viewModel = new SettingsViewModel(); viewModel.PrivateKey = profile.PrivateKey; viewModel.PublicKey = profile.PublicKey; return View(viewModel); }
public ActionResult Settings(SettingsViewModel model) { try { if (!string.IsNullOrWhiteSpace(model.OldPassword) && !string.IsNullOrWhiteSpace(model.NewPassword) && !string.IsNullOrWhiteSpace(model.ConfirmNewPassword)) { if (model.NewPassword == model.ConfirmNewPassword) { if (!WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) { ModelState.AddModelError("OldPassword", "Incorrect password"); return View(model); } } else { ModelState.AddModelError("NewPassword", ""); ModelState.AddModelError("ConfirmNewPassword", "Passwords don't match"); return View(model); } } int id = WebSecurity.GetUserId(WebSecurity.CurrentUserName); UserProfile profile = _context.UserProfiles.First(x => x.UserId == id); profile.PublicKey = model.PublicKey; profile.PrivateKey = model.PrivateKey; _context.SaveChanges(); } catch (Exception ex) { return View("Error"); } TempData["Notification"] = new Notification("Changes have been saved successfuly.", Nature.success); return View(model); }