Esempio n. 1
0
		public async Task<ActionResult> ManagePassword(ManagePasswordViewModel model)
		{
			ViewBag.ReturnUrl = Url.Action("ManagePassword");
			if (ModelState.IsValid)
			{
				var Db = new ApplicationDbContext();
				var user = Db.Users.First(u => u.Id == model.Id);

				IdentityResult result = await UserManager.RemovePasswordAsync(user.Id)
					.ContinueWith<IdentityResult>(resultTask =>
					{
						return UserManager.AddPasswordAsync(user.Id, model.NewPassword).Result;
					});

				if (result.Succeeded)
				{
					return RedirectToAction("Index");
				}
				else
				{
					AddErrors(result);
				}
			}
			// If we got this far, something failed, redisplay form
			return View(model);
		}
Esempio n. 2
0
		public ActionResult ManagePassword(string id, ManageMessageId? message)
		{
			ViewBag.StatusMessage =
				message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
				: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
				: message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
				: message == ManageMessageId.Error ? "An error has occurred."
				: "";
			var Db = new ApplicationDbContext();
			var user = Db.Users.First(u => u.Id == id);
			var model = new ManagePasswordViewModel(user);
			//ViewBag.HasLocalPassword = false;
			//ViewBag.ReturnUrl = Url.Action("ManagePassword");
			return View(model);
		}