-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a bunch of Sitecore.Analytics.Tracking.Contact extension methods. * Added a RedirectExtranetUsers attribute to force them to say their profile page if they try to hit a login/register page already signed in.
- Loading branch information
1 parent
e0bede1
commit 6a86dc8
Showing
15 changed files
with
1,965 additions
and
227 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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
11 changes: 11 additions & 0 deletions
11
CoreSitecore/Analytics/Model/Framework/IElementDictionaryExtensions.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Sitecore.Analytics.Model.Framework; | ||
|
||
public static class IElementDictionaryExtensions | ||
{ | ||
public static TElement GetSafely<TElement>(this IElementDictionary<TElement> dict, string key) | ||
where TElement : class, Sitecore.Analytics.Model.Framework.IElement | ||
{ | ||
return dict.Contains(key) ? dict[key] : null; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
using Sitecore.Analytics.Model.Entities; | ||
using Sitecore.Analytics.Tracking; | ||
using Sitecore.Social.Connector.Facets.Contact.SocialProfile; | ||
using System; | ||
|
||
public static class ContactExtensions | ||
{ | ||
#region Sitecore - Social Profiles | ||
|
||
public const string FacebookNetworkKey = "Facebook"; | ||
public const string GoogleNetworkKey = "Google"; | ||
public const string TwitterNetworkKey = "Twitter"; | ||
|
||
public static ISocialProfileFacet GetSocialProfile(this Contact contact) | ||
{ | ||
return contact.GetFacet<ISocialProfileFacet>("SocialProfile"); // Key must match Sitecore's configuration | ||
} | ||
|
||
/// <summary> | ||
/// Gets the first or default, so should only be used for registration social additional info page. | ||
/// </summary> | ||
/// <param name="contact"></param> | ||
/// <returns></returns> | ||
public static INetworkElement GetSocialProfileNetwork(this Contact contact, string providerKey) | ||
{ | ||
var socialProfile = contact.GetSocialProfile(); | ||
return socialProfile.Networks.GetSafely(providerKey); | ||
} | ||
|
||
public static INetworkElement GetFacebookNetwork(this Contact contact) | ||
{ | ||
return contact.GetSocialProfileNetwork(FacebookNetworkKey); | ||
} | ||
|
||
public static INetworkElement GetGoogleNetwork(this Contact contact) | ||
{ | ||
return contact.GetSocialProfileNetwork(GoogleNetworkKey); | ||
} | ||
|
||
public static INetworkElement GetTwitterNetwork(this Contact contact) | ||
{ | ||
return contact.GetSocialProfileNetwork(TwitterNetworkKey); | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Sitecore - Personal Info | ||
|
||
public static IContactPersonalInfo GetPersonalInfo(this Contact contact) | ||
{ | ||
return contact.GetFacet<IContactPersonalInfo>("Personal"); // Key must match Sitecore's configuration | ||
} | ||
|
||
public static string GetFirstName(this Contact contact) | ||
{ | ||
return (contact == null) ? String.Empty : contact.GetPersonalInfo().FirstName; | ||
} | ||
|
||
public static string GetSurname(this Contact contact) | ||
{ | ||
return (contact == null) ? String.Empty : contact.GetPersonalInfo().Surname; | ||
} | ||
|
||
public static string GetFirstNameInitial(this Contact contact) | ||
{ | ||
return GetInitial(contact.GetFirstName()); | ||
} | ||
|
||
public static string GetLastNameInitial(this Contact contact) | ||
{ | ||
return GetInitial(contact.GetFirstName()); | ||
} | ||
|
||
public static string GetInitial(string name) | ||
{ | ||
return string.IsNullOrWhiteSpace(name) ? String.Empty : name[0].ToString().ToUpper(); | ||
} | ||
|
||
public static string GetInitials(this Contact contact) | ||
{ | ||
return contact == null ? String.Empty : GetInitials(contact.GetFirstName(), contact.GetSurname()); | ||
} | ||
|
||
public static string GetInitials(string firstName, string lastName) | ||
{ | ||
return GetInitial(firstName) + GetInitial(lastName); | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Sitecore - Addresses | ||
|
||
public static IContactAddresses GetAddresses(this Contact contact) | ||
{ | ||
return contact.GetFacet<IContactAddresses>("Addresses"); // Key must match Sitecore's configuration | ||
} | ||
|
||
public static IAddress GetAddress(this Contact contact, string addressKey, bool createIfNotExists = false, bool makePreferred = false) | ||
{ | ||
var addresses = contact.GetAddresses(); | ||
|
||
IAddress address = null; | ||
if (addresses.Entries.Contains(addressKey)) | ||
{ | ||
address = addresses.Entries[addressKey]; | ||
} | ||
else if (createIfNotExists) | ||
{ | ||
address = addresses.Entries.Create(addressKey); | ||
} | ||
|
||
if (makePreferred) | ||
{ | ||
addresses.Preferred = addressKey; | ||
} | ||
|
||
return address; | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Sitecore - Emails | ||
|
||
public static IContactEmailAddresses GetEmails(this Contact contact) | ||
{ | ||
return contact.GetFacet<IContactEmailAddresses>("Emails"); // Key must match Sitecore's configuration | ||
} | ||
|
||
public static IEmailAddress GetEmail(this Contact contact, string emailKey, bool createIfNotExists = false, bool makePreferred = false) | ||
{ | ||
var emails = contact.GetEmails(); | ||
|
||
IEmailAddress email = null; | ||
if (emails.Entries.Contains(emailKey)) | ||
{ | ||
email = emails.Entries[emailKey]; | ||
} | ||
else if (createIfNotExists) | ||
{ | ||
email = emails.Entries.Create(emailKey); | ||
} | ||
|
||
if (makePreferred) | ||
{ | ||
emails.Preferred = emailKey; | ||
} | ||
|
||
return email; | ||
} | ||
|
||
#endregion | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Sitecore.Configuration; | ||
using Sitecore.Data; | ||
|
||
namespace CoreSitecore.Helpers | ||
{ | ||
public static class RedirectHelper | ||
{ | ||
/// <summary> | ||
/// Gets a redirect url from a Sitecore setting, | ||
/// whereby the setting value can be the ID of a Sitecore item to redirect to or a url to redirect to. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static string GetRedirectUrlFromSetting(string redirectUrlSettingName, string defaultRedirectUrlSettingName) | ||
{ | ||
var redirectionUrl = string.Empty; | ||
|
||
var settingName = string.IsNullOrWhiteSpace(redirectUrlSettingName) ? defaultRedirectUrlSettingName : redirectUrlSettingName; | ||
var settingValue = Settings.GetSetting(settingName); | ||
|
||
if (!string.IsNullOrWhiteSpace(settingValue)) | ||
{ | ||
// If ID, lookup item by ID and figure out it's URL | ||
if (ID.IsID(settingValue)) | ||
{ | ||
var itemToRedirectTo = Sitecore.Context.Database.GetItem(new ID(settingValue)); | ||
if (itemToRedirectTo != null) | ||
{ | ||
redirectionUrl = itemToRedirectTo.GetItemUrl(); | ||
} | ||
} | ||
else | ||
{ | ||
// Assume is url and just use that | ||
redirectionUrl = settingValue; | ||
} | ||
} | ||
|
||
return redirectionUrl; | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
CoreSitecore/Social/Connector/Facets/Contact/SocialProfile/IFieldElementExtensions.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Sitecore.Social.Connector.Facets.Contact.SocialProfile; | ||
|
||
public static class IFieldElementExtensions | ||
{ | ||
public static string GetValueOrDefault(this IFieldElement fieldEle) | ||
{ | ||
return fieldEle == null ? null : fieldEle.Value; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CoreSitecore.Helpers; | ||
using System.Web.Mvc; | ||
|
||
namespace CoreSitecore.Sys.Web.Mvc | ||
{ | ||
/// <summary> | ||
/// An action filter attribute that checks if a user is authenticated and authenticated under the extranet domain. | ||
/// If so, it will enforce a redirection to a configured url/item. | ||
/// </summary> | ||
public class RedirectExtranetUsers : ActionFilterAttribute | ||
{ | ||
private const string DefaultRedirectUrlSettingName = "CoreSitecore.ActionFilters.DefaultRedirectExtranetUrl"; | ||
|
||
/// <summary> | ||
/// Extranet users (i.e. IsAuthenticated and under extranet domain) will be redirected to a url found by inspecting this setting. | ||
/// | ||
/// If this setting is an Sitecore.Data.ID, the url to that item will be used. | ||
/// Else, it will be assumed to be a URL that can be redirected to as is. | ||
/// | ||
/// Default: "CoreSitecore.ActionFilters.DefaultRedirectExtranetUrl" | ||
/// </summary> | ||
public string RedirectUrlSettingName { get; set; } | ||
|
||
public override void OnActionExecuting(ActionExecutingContext filterContext) | ||
{ | ||
if (Sitecore.Context.User.IsAuthenticated && Sitecore.Context.User.GetDomainName() == "extranet") | ||
{ | ||
var redirectionUrl = RedirectHelper.GetRedirectUrlFromSetting(RedirectUrlSettingName, DefaultRedirectUrlSettingName); | ||
|
||
if (!string.IsNullOrWhiteSpace(redirectionUrl)) | ||
{ | ||
filterContext.Result = new RedirectResult(redirectionUrl); | ||
return; | ||
} | ||
} | ||
|
||
base.OnActionExecuting(filterContext); | ||
} | ||
} | ||
} |