From d4c0e7dd90ea23ba1f56eeb453654ff6aaf28101 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Tue, 15 Apr 2014 12:23:21 -0700 Subject: [PATCH] Remove set password logic not needed for alpha --- .../Controllers/AccountController.cs | 75 +++---------------- src/MusicStore/Startup.cs | 1 + 2 files changed, 12 insertions(+), 64 deletions(-) diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index 3bc5f3ba08..1aa0e88e0c 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -126,11 +126,8 @@ namespace MusicStore.Controllers { 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." : ""; - ViewBag.HasLocalPassword = await HasPassword(); ViewBag.ReturnUrl = Url.Action("Manage"); return View(); } @@ -141,51 +138,20 @@ namespace MusicStore.Controllers //[ValidateAntiForgeryToken] public async Task Manage(ManageUserViewModel model) { - bool hasPassword = await HasPassword(); - ViewBag.HasLocalPassword = hasPassword; ViewBag.ReturnUrl = Url.Action("Manage"); - if (hasPassword) + if (ModelState.IsValid == true) { - if (ModelState.IsValid == true) + var user = await GetCurrentUserAsync(); + var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); + if (result.Succeeded) { - var user = await GetCurrentUser(); - var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); - if (result.Succeeded) - { - return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); - } - else - { - AddErrors(result); - } + return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); + } + else + { + AddErrors(result); } } - else - { - // User does not have a password so remove any validation errors caused by a missing OldPassword field - ModelState state = null; - ModelState.TryGetValue("OldPassword", out state); - - if (state != null) - { - state.Errors.Clear(); - } - - if (ModelState.IsValid == true) - { - var user = await GetCurrentUser(); - var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); - if (result.Succeeded) - { - return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }); - } - else - { - AddErrors(result); - } - } - } - // If we got this far, something failed, redisplay form return View(model); } @@ -196,8 +162,7 @@ namespace MusicStore.Controllers //[ValidateAntiForgeryToken] public IActionResult LogOff() { - // Bug: This should call SignInManager.SignOut() once its available - this.Context.Response.SignOut(); + SignInManager.SignOut(); return RedirectToAction("Index", "Home"); } @@ -211,21 +176,11 @@ namespace MusicStore.Controllers } } - private async Task GetCurrentUser() + private async Task GetCurrentUserAsync() { return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId()); } - private async Task HasPassword() - { - var user = await GetCurrentUser(); - if (user != null) - { - return await UserManager.HasPasswordAsync(user); - } - return false; - } - public enum ManageMessageId { ChangePasswordSuccess, @@ -311,12 +266,4 @@ namespace MusicStore.Controllers return claim != null ? claim.Value : null; } } - - /// - /// TODO: Temporary APIs to unblock build. Need to remove this once we have these APIs available. - /// - public static class DefaultAuthenticationTypes - { - public const string ApplicationCookie = "Application"; - } } \ No newline at end of file diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 6a4ed6a2c2..a91d739a28 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.InMemory; +using Microsoft.AspNet.Identity.Security; using Microsoft.AspNet.Logging; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.RequestContainer;