From 025d366b83407c14e8b1448ca6d0fc5ca75a3059 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Fri, 9 Feb 2018 14:08:01 -0800 Subject: [PATCH] Fix bad merge --- .../Controllers/AccountController.cs | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs index c364589451..56380808a2 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs @@ -21,7 +21,7 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult SignIn() { - var redirectUrl = Url.Page("/Index"); + var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); return Challenge( new AuthenticationProperties { RedirectUri = redirectUrl }, OpenIdConnectDefaults.AuthenticationScheme @@ -31,12 +31,24 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult SignOut() { - var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme); + var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme); return SignOut( new AuthenticationProperties { RedirectUri = callbackUrl }, CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme ); } + + [HttpGet] + public IActionResult SignedOut() + { + if (User.Identity.IsAuthenticated) + { + // Redirect to home page if the user is authenticated. + return RedirectToAction(nameof(HomeController.Index), "Home"); + } + + return View(); + } #elseif (IndividualB2CAuth) private readonly AzureAdB2COptions _options; @@ -48,7 +60,7 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult SignIn() { - var redirectUrl = Url.Page("/Index"); + var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); return Challenge( new AuthenticationProperties { RedirectUri = redirectUrl }, OpenIdConnectDefaults.AuthenticationScheme @@ -58,7 +70,7 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult ResetPassword() { - var redirectUrl = Url.Page("/Index"); + var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.ResetPasswordPolicyId; return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme); @@ -67,7 +79,7 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult EditProfile() { - var redirectUrl = Url.Page("/Index"); + var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.EditProfilePolicyId; return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme); @@ -76,12 +88,23 @@ namespace Company.WebApplication1.Controllers [HttpGet] public IActionResult SignOut() { - var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme); + var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme); return SignOut( new AuthenticationProperties { RedirectUri = callbackUrl }, CookieAuthenticationDefaults.AuthenticationScheme, - OpenIdConnectDefaults.AuthenticationScheme - ); + OpenIdConnectDefaults.AuthenticationScheme); + } + + [HttpGet] + public IActionResult SignedOut() + { + if (User.Identity.IsAuthenticated) + { + // Redirect to home page if the user is authenticated. + return RedirectToAction(nameof(HomeController.Index), "Home"); + } + + return View(); } #endif