This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from Sitecore/feature/Authentication
Refactored redirect logic for Authentication
- Loading branch information
Showing
66 changed files
with
1,355 additions
and
481 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
src/Feature/Accounts/Tests/Attributes/AccountsRedirectAuthenticatedAttributeTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 11 additions & 12 deletions
23
src/Feature/Accounts/code/App_Config/Include/Feature/Feature.Accounts.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | ||
<sitecore> | ||
<settings> | ||
<setting name="Sitecore.Feature.Accounts.LoginGoalId" value="{66722F52-2D13-4DCC-90FC-EA7117CF2298}" /> | ||
<setting name="Sitecore.Feature.Accounts.RegisterGoalId" value="{8FFB183B-DA1A-4C74-8F3A-9729E9FCFF6A}" /> | ||
</settings> | ||
<pipelines> | ||
<initialize> | ||
<processor type="Sitecore.Feature.Accounts.Pipelines.RegisterWebApiRoutes, Sitecore.Feature.Accounts" | ||
patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" /> | ||
</initialize> | ||
</pipelines> | ||
</sitecore> | ||
<sitecore> | ||
<settings> | ||
<setting name="Sitecore.Feature.Accounts.LoginGoalId" value="{66722F52-2D13-4DCC-90FC-EA7117CF2298}" /> | ||
<setting name="Sitecore.Feature.Accounts.RegisterGoalId" value="{8FFB183B-DA1A-4C74-8F3A-9729E9FCFF6A}" /> | ||
</settings> | ||
<pipelines> | ||
<initialize> | ||
<processor type="Sitecore.Feature.Accounts.Pipelines.RegisterWebApiRoutes, Sitecore.Feature.Accounts" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" /> | ||
</initialize> | ||
</pipelines> | ||
</sitecore> | ||
</configuration> |
25 changes: 0 additions & 25 deletions
25
src/Feature/Accounts/code/Attributes/AccountsRedirectAuthenticatedAttribute.cs
This file was deleted.
Oops, something went wrong.
45 changes: 22 additions & 23 deletions
45
src/Feature/Accounts/code/Attributes/RedirectAuthenticatedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
namespace Sitecore.Feature.Accounts.Attributes | ||
{ | ||
using System; | ||
using System.Web.Mvc; | ||
using Sitecore.Foundation.SitecoreExtensions.Extensions; | ||
using System.Web.Mvc; | ||
using Sitecore.Feature.Accounts.Services; | ||
|
||
public class RedirectAuthenticatedAttribute : ActionFilterAttribute | ||
{ | ||
public override void OnActionExecuting(ActionExecutingContext filterContext) | ||
public class RedirectAuthenticatedAttribute : ActionFilterAttribute | ||
{ | ||
if (!Context.PageMode.IsNormal) | ||
return; | ||
if (!Context.User.IsAuthenticated) | ||
return; | ||
var link = this.GetRedirectUrl(filterContext); | ||
if (filterContext.HttpContext.Request.RawUrl.Equals(link, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
link = this.RedirectUrl; | ||
} | ||
private readonly IGetRedirectUrlService getRedirectUrlService; | ||
|
||
filterContext.Result = new RedirectResult(link); | ||
} | ||
public RedirectAuthenticatedAttribute() : this(new GetRedirectUrlService()) | ||
{ | ||
} | ||
|
||
protected virtual string GetRedirectUrl(ActionExecutingContext filterContext) | ||
{ | ||
return this.RedirectUrl; | ||
} | ||
public RedirectAuthenticatedAttribute(IGetRedirectUrlService getRedirectUrlService) | ||
{ | ||
this.getRedirectUrlService = getRedirectUrlService; | ||
} | ||
|
||
private string RedirectUrl => Context.Site.GetRootItem().Url(); | ||
} | ||
|
||
public override void OnActionExecuting(ActionExecutingContext filterContext) | ||
{ | ||
if (!Context.PageMode.IsNormal) | ||
return; | ||
if (!Context.User.IsAuthenticated) | ||
return; | ||
var link = this.getRedirectUrlService.GetRedirectUrl(AuthenticationStatus.Authenticated); | ||
filterContext.Result = new RedirectResult(link); | ||
} | ||
} | ||
} |
33 changes: 23 additions & 10 deletions
33
src/Feature/Accounts/code/Attributes/RedirectUnauthenticatedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
namespace Sitecore.Feature.Accounts.Attributes | ||
{ | ||
using System.Web.Mvc; | ||
using Sitecore.Foundation.SitecoreExtensions.Extensions; | ||
using System; | ||
using System.Web.Mvc; | ||
using Sitecore.Feature.Accounts.Services; | ||
using Sitecore.Foundation.SitecoreExtensions.Extensions; | ||
|
||
public class RedirectUnauthenticatedAttribute : ActionFilterAttribute, IAuthorizationFilter | ||
{ | ||
public void OnAuthorization(AuthorizationContext filterContext) | ||
public class RedirectUnauthenticatedAttribute : ActionFilterAttribute, IAuthorizationFilter | ||
{ | ||
if (!Context.User.IsAuthenticated) | ||
{ | ||
filterContext.Result = new RedirectResult(Context.Site.GetRootItem().Url()); | ||
} | ||
private readonly IGetRedirectUrlService getRedirectUrlService; | ||
|
||
public RedirectUnauthenticatedAttribute() : this(new GetRedirectUrlService()) | ||
{ | ||
} | ||
|
||
private RedirectUnauthenticatedAttribute(IGetRedirectUrlService getRedirectUrlService) | ||
{ | ||
this.getRedirectUrlService = getRedirectUrlService; | ||
} | ||
|
||
public void OnAuthorization(AuthorizationContext context) | ||
{ | ||
if (Context.User.IsAuthenticated) | ||
return; | ||
var link = this.getRedirectUrlService.GetRedirectUrl(AuthenticationStatus.Unauthenticated, context.HttpContext.Request.RawUrl); | ||
context.Result = new RedirectResult(link); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.