diff --git a/CoreSitecore.Tests/Properties/AssemblyInfo.cs b/CoreSitecore.Tests/Properties/AssemblyInfo.cs index fac3586..a239eee 100644 --- a/CoreSitecore.Tests/Properties/AssemblyInfo.cs +++ b/CoreSitecore.Tests/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("8.1.3.0")] -[assembly: AssemblyFileVersion("8.1.3.0")] +[assembly: AssemblyVersion("8.1.4.0")] +[assembly: AssemblyFileVersion("8.1.4.0")] diff --git a/CoreSitecore/CoreSitecore.csproj b/CoreSitecore/CoreSitecore.csproj index 29d861b..134a700 100644 --- a/CoreSitecore/CoreSitecore.csproj +++ b/CoreSitecore/CoreSitecore.csproj @@ -89,6 +89,7 @@ + @@ -97,6 +98,8 @@ + + diff --git a/CoreSitecore/Properties/AssemblyInfo.cs b/CoreSitecore/Properties/AssemblyInfo.cs index 8d9e34b..7e119ed 100644 --- a/CoreSitecore/Properties/AssemblyInfo.cs +++ b/CoreSitecore/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("8.1.3.0")] -[assembly: AssemblyFileVersion("8.1.3.0")] +[assembly: AssemblyVersion("8.1.4.0")] +[assembly: AssemblyFileVersion("8.1.4.0")] diff --git a/CoreSitecore/Sys/ComponentModel/ScDisplayNameAttribute.cs b/CoreSitecore/Sys/ComponentModel/ScDisplayNameAttribute.cs new file mode 100644 index 0000000..e627270 --- /dev/null +++ b/CoreSitecore/Sys/ComponentModel/ScDisplayNameAttribute.cs @@ -0,0 +1,32 @@ +using Sitecore.Globalization; +using System.ComponentModel; + +namespace CoreSitecore.Sys.ComponentModel +{ + /// + /// A DisplayName attribute that gets the text to use from the Sitecore Dictionary (localised to current language). + /// + /// A better solution though is to use + /// + public class ScDisplayNameAttribute : DisplayNameAttribute + { + private readonly string _dictionaryKey; + + /// + /// Initializes a DisplayName field attribute that gets its text from the Sitecore Dictionary using . + /// + /// Key to lookup in Sitecore Dictionary. + public ScDisplayNameAttribute(string dictionaryKey) + { + _dictionaryKey = dictionaryKey; + } + + public override string DisplayName + { + get + { + return Translate.Text(_dictionaryKey); + } + } + } +} diff --git a/CoreSitecore/Sys/Web/Mvc/AuthorizeByDomainAttribute.cs b/CoreSitecore/Sys/Web/Mvc/AuthorizeByDomainAttribute.cs new file mode 100644 index 0000000..68842f4 --- /dev/null +++ b/CoreSitecore/Sys/Web/Mvc/AuthorizeByDomainAttribute.cs @@ -0,0 +1,40 @@ +using System; +using System.Web; +using System.Web.Mvc; + +namespace CoreSitecore.Sys.Web.Mvc +{ + /// + /// An AuthorizeByDomain attribute implementation that checks the current Sitecore.Context.User is not null, authenticated and belongs to extranet domain. + /// + public class AuthorizeByDomainAttribute : AuthorizeAttribute + { + private readonly string _domainName; + + /// + /// If specified, on an unauthorized request, user will be redirected to this url. + /// + public string RedirectToUrl { get; set; } + + public AuthorizeByDomainAttribute(string domainName) + { + _domainName = domainName; + } + + protected override bool AuthorizeCore(HttpContextBase httpContext) + { + var user = Sitecore.Context.User; + return user != null && user.IsAuthenticated && user.GetDomainName().Equals(_domainName, StringComparison.OrdinalIgnoreCase); + } + + protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) + { + if (!string.IsNullOrWhiteSpace(RedirectToUrl)) + { + filterContext.Result = new RedirectResult(RedirectToUrl); + } + + base.HandleUnauthorizedRequest(filterContext); + } + } +} diff --git a/CoreSitecore/Sys/Web/Mvc/AuthorizeExtranetAttribute.cs b/CoreSitecore/Sys/Web/Mvc/AuthorizeExtranetAttribute.cs new file mode 100644 index 0000000..890779d --- /dev/null +++ b/CoreSitecore/Sys/Web/Mvc/AuthorizeExtranetAttribute.cs @@ -0,0 +1,14 @@ +namespace CoreSitecore.Sys.Web.Mvc +{ + /// + /// An Authorize attribute implementation that checks the current Sitecore.Context.User is not null, authenticated and belongs to extranet domain. + /// + public class AuthorizeExtranetAttribute : AuthorizeByDomainAttribute + { + public AuthorizeExtranetAttribute() + : base("extranet") + { + + } + } +}