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.
To see if someone is signed in, examine the cookie “wv_user_info”. That cookie will provide the following information:
|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.
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).
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.
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.
For an example of code that uses these functions, see the article User Management Pages.