Persisted Login with Web Forms for Marketers

When creating a new WFFM form administrators choose a Submit Action. If the “S4S Push Visitor” Submit Action is chosen, a “S4SPersistedLogin” cookie is created in browser of the visitor submitting the form. You can choose to use or ignore this cookie.

You can use the “S4SPersistedLogin” cookie to identify the visitor if they return to the website at a future date. The identification is possible because the Salesforce Lead (or Contact) record (created when the WFFM form was submitted) contains a unique (and configurable) field that transparently logs the user into the Sitecore website. This functionality requires the S4S Security Provider be installed (in this scenario the Sitecore website may or may not have traditional authentication via a login control).

If you do not want to uses the “S4S Push Visitor” Submit Action you can create your own custom functionality. The S4SPersistedLogin methods can be found in the PersistedLogin class in the FuseIT.S4SMapping.dll assembly. Its exposes the following methods:

Creating a Cookie

Use the following static method to create a cookie. This method is used in the “S4S Push Visitor” Submit Action but can also be accessed on a custom form.

 

PersistedLogin.CreateLoginCookie(visitorId, loginUserName, expires);

Auto-Login

After a cookie is created, we need to identify and login the returning visitor:

 

PersistedLogin persistedLogin = new PersistedLogin(Request);
string userLoginName = string.Empty;
if (persistedLogin.ValidateLoginCookie("salesforce", out userLoginName))
{
Sitecore.Security.Authentication.AuthenticationManager.Login(userLoginName);
}

Logout

There are two types of logout. Permanent logout will delete the “S4SPersistedLogin” cookie while another creates a new cookie to block auto login. The block cookie will be removed when the user’s session ends, so next time user comes back, that user will be able to auto login again.

 

/// <summary>
/// Permanent log out
/// </summary>
PersistedLogin persistedLogin = new PersistedLogin(Request);
persistedLogin.PermanentLogoutUser();
 
/// <summary>
/// Create a cookie to block auto logins
/// </summary>
PersistedLogin persistedLogin = new PersistedLogin(Request);
persistedLogin.LogoutUser();