31.10.2014 Views

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

98 | Developer’s <strong>Guide</strong> <strong>EPiServer</strong> Community 3.1<br />

2.24 OnlineStatus<br />

The <strong>EPiServer</strong> Community OnlineStatus module provides the tools to see which users are logged in to the site.<br />

Functionality includes seeing if a user is currently online, getting the date that a user was last online and getting a list of<br />

the last logged in users.<br />

2.24.1 Seeing if a User is Online<br />

It is easy to see if a user is currently online. This can be used on the site to indicate the user’s status.<br />

Import Necessary Namespaces<br />

First, import the necessary namespaces that will be used to see if a user is online. The namespaces<br />

StarCommunity.Core, StarCommunity.Core.Modules.Security and StarCommunity.Modules.OnlineStatus are described<br />

by clicking on their respective names. Make sure you add the assembly as a reference, mentioned in section 1.1.1.<br />

using StarCommunity.Core;<br />

using StarCommunity.Core.Modules.Security;<br />

using StarCommunity.Modules.OnlineStatus;<br />

Seeing if a User is Online<br />

The following code shows how to retrieve a user and to determine the online status.<br />

//Get the logged in user<br />

IUser user = (IUser)StarCommunitySystem.<br />

CurrentContext.DefaultSecurity.GetUser(1234);<br />

//Flag to see if the user is online<br />

bool isOnline = OnlineStatusModule.IsOnline(user);<br />

2.24.2 Getting a User’s Last Login Date<br />

The OnlineStatus module provides functionality to return a date indicating the date and time that a user was last online.<br />

This date can then for example be displayed on the user’s profile page.<br />

Import Necessary Namespaces<br />

First, import the necessary namespaces that will be used to see if a user is online. The namespaces<br />

StarCommunity.Core, StarCommunity.Core.Modules.Security and StarCommunity.Modules.OnlineStatus are described<br />

by clicking on their respective names. Make sure you add the assembly as a reference, mentioned in section 1.1.1.<br />

using StarCommunity.Core;<br />

using StarCommunity.Core.Modules.Security;<br />

using StarCommunity.Modules.OnlineStatus;<br />

© <strong>EPiServer</strong> AB

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!