Remove set password logic not needed for alpha

This commit is contained in:
Hao Kung 2014-04-15 12:23:21 -07:00
parent 7fd711df54
commit d4c0e7dd90
2 changed files with 12 additions and 64 deletions

View File

@ -126,11 +126,8 @@ namespace MusicStore.Controllers
{ {
ViewBag.StatusMessage = ViewBag.StatusMessage =
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." 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." : message == ManageMessageId.Error ? "An error has occurred."
: ""; : "";
ViewBag.HasLocalPassword = await HasPassword();
ViewBag.ReturnUrl = Url.Action("Manage"); ViewBag.ReturnUrl = Url.Action("Manage");
return View(); return View();
} }
@ -141,51 +138,20 @@ namespace MusicStore.Controllers
//[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public async Task<IActionResult> Manage(ManageUserViewModel model) public async Task<IActionResult> Manage(ManageUserViewModel model)
{ {
bool hasPassword = await HasPassword();
ViewBag.HasLocalPassword = hasPassword;
ViewBag.ReturnUrl = Url.Action("Manage"); 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(); return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); }
if (result.Succeeded) else
{ {
return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); AddErrors(result);
}
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 // If we got this far, something failed, redisplay form
return View(model); return View(model);
} }
@ -196,8 +162,7 @@ namespace MusicStore.Controllers
//[ValidateAntiForgeryToken] //[ValidateAntiForgeryToken]
public IActionResult LogOff() public IActionResult LogOff()
{ {
// Bug: This should call SignInManager.SignOut() once its available SignInManager.SignOut();
this.Context.Response.SignOut();
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }
@ -211,21 +176,11 @@ namespace MusicStore.Controllers
} }
} }
private async Task<ApplicationUser> GetCurrentUser() private async Task<ApplicationUser> GetCurrentUserAsync()
{ {
return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId()); return await UserManager.FindByIdAsync(Context.User.Identity.GetUserId());
} }
private async Task<bool> HasPassword()
{
var user = await GetCurrentUser();
if (user != null)
{
return await UserManager.HasPasswordAsync(user);
}
return false;
}
public enum ManageMessageId public enum ManageMessageId
{ {
ChangePasswordSuccess, ChangePasswordSuccess,
@ -311,12 +266,4 @@ namespace MusicStore.Controllers
return claim != null ? claim.Value : null; return claim != null ? claim.Value : null;
} }
} }
/// <summary>
/// TODO: Temporary APIs to unblock build. Need to remove this once we have these APIs available.
/// </summary>
public static class DefaultAuthenticationTypes
{
public const string ApplicationCookie = "Application";
}
} }

View File

@ -7,6 +7,7 @@ using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.InMemory; using Microsoft.AspNet.Identity.InMemory;
using Microsoft.AspNet.Identity.Security;
using Microsoft.AspNet.Logging; using Microsoft.AspNet.Logging;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.RequestContainer; using Microsoft.AspNet.RequestContainer;