Blog

Sitecore 7.5 highlights

MongoMemeHi, welcome to my Sitecore 7.5 highlights.

This blog post is intended for those of you who would like a high level overview of Sitecore 7.5, need a reminder or have not had the time to investigate this release. At the bottom of this post is a list of useful resources related to Sitecore 7.5.

Highlights

  1. Sitecore 7.5 = Sitecore 7.2 + xDB.
  2. xDB (Experience Database) is the new name for the Analytics database.
  3. New Contact entity allows tracking an individual across devices, visits and cookies.
    • Requires some sort of mechanism of identifying the user( login, form submission, checkout etc)
  4. New scalable analytics data architecture
    • Session DB (private and shared) (inProc, Sql or Mongo)
    • Collection DB i.e. xDB (Mongo)
    • Reporting DB (SQL)
  5. Experience profile (xFile) i.e the contact
  6. xDB Cloud
    • Sitecores cloud hosting offering for xDB
    • Pricing based on numbers of stored contacts.
  7. Mongo DB
    • Data stored in documents not tables
    • Collections of documents rather than tables with rows.
    • Scales horizontally not vertically
    • Data stored in BSON binary Json
  8. Upgrade key points
    • Analytics API has many small changes
    • Migration of data from Analytics DB to xDB i.e. SQL to Mongo
    • Review of hosting structure to suit xDB.
  9. Other name changes:
    • Customer Engagement Platform = Sitecore Experience Platform (Sitecore XP)
    • Digital Marketing System (DMS) = Experience Marketing
    • Email Campaign Manger = Email Experience Manager
    • Engagement Analytics = Experience Analytics
    • Adaptive Print Studio = Print Experience Manger
    • Engagement Automation = Experience Automation

Sitecore 7.5 Resources

Sitecore membership guide

join1Below is a core list of commonly used authentication and authorization methods to act like a quick reference guide for people building membership based Sitecore solutions.

This reference is intended to get you on the right track immediately from the one source.

If anyone has anything they would like me to add to the list please comment below and I’ll update it accordingly.

Using

These are the required references for the following examples:

using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore;
using Sitecore.Security;
using Sitecore.Security.Accounts;
using System.Web.Security;
using Sitecore.Security.Authentication;

Retrieving Users

//Get all users regardless of domain, Sitecore, extranet, custom etc:
public IEnumerable<User> GetUsers()
{
return UserManager.GetUsers();
}

//Get all users for a particular domain, in most situations this will be of more use then getting all users:
public IEnumerable<User> GetUsers(string domainName)
{
return UserManager.GetUsers().Where(user => user.Domain != null && user.Domain.Name == domainName);
}

//Get a user from a custom property. This can be useful to find a user by some unique value.
public User GetUserFromCustomField(string fieldName, string fieldValue)
{
return UserManager.GetUsers().FirstOrDefault(user => user.Profile.GetCustomProperty(fieldName) == fieldValue);
}

//Get a collection of users from a custom property. An example might be to get all male users.
public IEnumerable<User> GetUsersFromCustomField(string fieldName, string fieldValue)
{
return UserManager.GetUsers().Where(user => user.Profile.GetCustomProperty(fieldName) == fieldValue);
}

//Again with queries like this it is most likely that filtering by domain name will be more useful then searching all users.
public User GetUserFromCustomField(string fieldName, string fieldValue, string domainName)
{
return UserManager.GetUsers().FirstOrDefault(user => user.Profile.GetCustomProperty(fieldName) == fieldValue && user.Domain.Name == domainName);
}

public IEnumerable<User> GetUsersFromCustomField(string fieldName, string fieldValue, string domainName)
{
return UserManager.GetUsers().Where(user => user.Profile.GetCustomProperty(fieldName) == fieldValue && user.Domain.Name == domainName);
}

//Get user by user name, it must include the domain.
public User GetUserByUserName(string domainName, string userName)
{
return User.FromName(String.Format(@"{0}\{1}", domainName, userName), false);
}

//Get user by email, first get the username for the email then get user by username.
public User GetUserByEmail(string domainName, string email)
{
var userName = Membership.GetUserNameByEmail(email);
return !String.IsNullOrEmpty(userName) ? GetUserByUserName(userName, domainName) : null;
}

//Check if a user exists
public bool DoesUserExist(string domainName, string userName)
{
return User.Exists(String.Format(@"{0}\{1}", domainName, userName));
}

//Get the current context user. This will by default be extranet\Anonymous if no one is logged in.
public User GetCurrentUser()
{
return Context.User;
}

Users Roles

public  IEnumerable<Role> GetUsersRoles(UserProfile profile)
{
return profile.ProfileUser.Roles;
}

public void AddRoleToUser(UserProfile profile, string roleName, string domainName)
{
profile.ProfileUser.Roles.Add(RoleHelper.GetRole(domainName, roleName));
profile.Save();
}

public void RemoveRoleFromUser(UserProfile profile, string roleName, string domainName)
{
profile.ProfileUser.Roles.Remove(RoleHelper.GetRole(domainName, roleName));
profile.Save();
}

public bool IsUserInRole(User user, string role)
{
return user != null && user.IsInRole(role);
}

User CRUD

public void AddUser(string domainName, string userName, string password, string email)
{
Membership.CreateUser(String.Format(@"{0}\{1}", domainName, userName), password, email);
}

public string GetUsersCutomProperty(User user, string fieldName)
{
return user.Profile.GetCustomProperty(fieldName);
}

//Update the Users default sitecore and custom fields
public void UpdateUser(UserProfile profile, string email, string fullName, string customFieldName, string customFieldValue)
{
profile.Email = email;
profile.FullName = fullName;
profile.SetCustomProperty(customFieldName, customFieldValue);
profile.Save();
}

public void DeleteUser(User user)
{
user.Delete();
}

Is authenticated, is administrator

//Method not required but here for completeness
public bool IsUserAuthenticated(User user)
{
return user.IsAuthenticated;
}

//Method not required but here for completeness
public bool IsUserAdministrator(User user)
{
return user.IsAdministrator;
}

Change and reset users password

public void ChangeUsersPassword(string userName, string currentPassword, string newPassword)
{
Membership.Provider.ChangePassword(userName, currentPassword, newPassword);
}

public static string ResetUsersPassword(string userName)
{
var membershipUser = Membership.GetUser(userName);
return membershipUser != null ? membershipUser.ResetPassword() : string.Empty;
}

Authentication

//login without password
public void LoginUser(string domainName, string userName)
{
AuthenticationManager.Login(string.Format(@"{0}\{1}", domainName, userName), false);
}

//default login
public void LoginUser(string domainName, string userName, string password)
{
AuthenticationManager.Login(string.Format(@"{0}\{1}", domainName, userName), password, false);
}

public void LogOutUser()
{
AuthenticationManager.Logout();
}

Roles

//Roles are seperate per domain
public Role GetRole(string domainName, string roleName)
{
return Role.FromName(string.Format(@"{0}\{1}", domainName, roleName));
}

public IEnumerable<string> GetRoles()
{
return Roles.GetAllRoles();
}

public IEnumerable<string> GetRoles(string domainName)
{
return Roles.GetAllRoles().Where(r => r.Contains(domainName));
}