Accessing Current User Information

When displaying a page of your site, you may want to know whether someone is logged in, as well as information about that user. You can use this capability to, for example, display "Edit Profile" and "Log Out" links only if someone is logged in, or to display a "Welcome John Smith" message.

You can access the user information in WebvantaScript, but if you take this approach, you must set the page type to "Ajax" to prevent the page from being cached. Otherwise, one user may see the cached information stored by another user.

The best way to avoid this problem, and to allow cached pages to be customized, is to use JavaScript to modify the cached, unpersonalized page.

To see if someone is signed in, examine the cookie “wv_user_info”. That cookie will provide the following information:

Key Value Note
v 2 version of wv_user_info string
r (role) will be either ‘admin’, ‘member’ a site-specific role, or a delimited list of roles (you should try to split on comma or pipe '|' characters)
name (user’s full name) This is their display name made up of first and last name
login (user’s email address) This is user's email address, used as their login when accessing the site
company_name (company name) Whatever is set in the company_name Config setting for the site

There are other fields in the cookie, but they are reserved for internal use and can change without notification.

Using the WebvantaAdmin JavaScript Object

A WebvantaAdmin JavaScript object is automatically injected into your site's code, so it is always available for you to use. It contains some useful functions that you can use to work with user information (and with cookies in general).

Note: You should check the WebvantaAdmin.version string if you depend on these APIs, as behavior can change between major and minor dot releases (but typically not bug fix releases).

In particular, WebvantaAdmin.readCookie(name) may be useful if you don’t have your own cookie-reading code in use yet. It returns the value of the cookie with the specified name, provided that such a cookie exists.

In addition, WebvantaAdmin.getUIRValue(key); is a shortcut to read the above values. For example, WebvantaAdmin.getUIRValue("name"); will return the name of the currently logged-in user.

You should only use the above routines from within a DOM ready handler, as with most JavaScript code.

For an example of code that uses these functions, see the article User Management Pages.