React to identity changes

This commit is contained in:
Hao Kung 2016-01-14 13:12:41 -08:00
parent 7463dee1d5
commit 5c623b6e80
4 changed files with 10 additions and 10 deletions

View File

@ -395,7 +395,7 @@ namespace MusicStore.Controllers
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null) public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
{ {
if (User.IsSignedIn()) if (SignInManager.IsSignedIn(User))
{ {
return RedirectToAction("Index", "Manage"); return RedirectToAction("Index", "Manage");
} }
@ -476,9 +476,9 @@ namespace MusicStore.Controllers
} }
} }
private async Task<ApplicationUser> GetCurrentUserAsync() private Task<ApplicationUser> GetCurrentUserAsync()
{ {
return await UserManager.FindByIdAsync(HttpContext.User.GetUserId()); return UserManager.GetUserAsync(HttpContext.User);
} }
private ActionResult RedirectToLocal(string returnUrl) private ActionResult RedirectToLocal(string returnUrl)

View File

@ -48,7 +48,7 @@ namespace MusicStore.Controllers
} }
else else
{ {
order.Username = HttpContext.User.GetUserName(); order.Username = HttpContext.User.Identity.Name;
order.OrderDate = DateTime.Now; order.OrderDate = DateTime.Now;
//Add the Order //Add the Order
@ -81,7 +81,7 @@ namespace MusicStore.Controllers
// Validate customer owns this order // Validate customer owns this order
bool isValid = await dbContext.Orders.AnyAsync( bool isValid = await dbContext.Orders.AnyAsync(
o => o.OrderId == id && o => o.OrderId == id &&
o.Username == HttpContext.User.GetUserName()); o.Username == HttpContext.User.Identity.Name);
if (isValid) if (isValid)
{ {

View File

@ -300,7 +300,7 @@ namespace MusicStore.Controllers
{ {
// Request a redirect to the external login provider to link a login for the current user // Request a redirect to the external login provider to link a login for the current user
var redirectUrl = Url.Action("LinkLoginCallback", "Manage"); var redirectUrl = Url.Action("LinkLoginCallback", "Manage");
var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.GetUserId()); var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, UserManager.GetUserId(User));
return new ChallengeResult(provider, properties); return new ChallengeResult(provider, properties);
} }
@ -314,7 +314,7 @@ namespace MusicStore.Controllers
return View("Error"); return View("Error");
} }
var loginInfo = await SignInManager.GetExternalLoginInfoAsync(User.GetUserId()); var loginInfo = await SignInManager.GetExternalLoginInfoAsync(await UserManager.GetUserIdAsync(user));
if (loginInfo == null) if (loginInfo == null)
{ {
return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }); return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error });
@ -347,9 +347,9 @@ namespace MusicStore.Controllers
Error Error
} }
private async Task<ApplicationUser> GetCurrentUserAsync() private Task<ApplicationUser> GetCurrentUserAsync()
{ {
return await UserManager.FindByIdAsync(HttpContext.User.GetUserId()); return UserManager.GetUserAsync(HttpContext.User);
} }
#endregion #endregion

View File

@ -121,7 +121,7 @@ namespace MusicStore
// administrator. But this can be changed to suit the needs. // administrator. But this can be changed to suit the needs.
var identity = (ClaimsIdentity)context.User.Identity; var identity = (ClaimsIdentity)context.User.Identity;
if (context.User.GetUserName() == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" if (context.User.Identity.Name == Environment.GetEnvironmentVariable("USERDOMAIN") + "\\"
+ Environment.GetEnvironmentVariable("USERNAME")) + Environment.GetEnvironmentVariable("USERNAME"))
{ {
identity.AddClaim(new Claim("ManageStore", "Allowed")); identity.AddClaim(new Claim("ManageStore", "Allowed"));