User Bean - Mura Docs v7.0

User Bean

The user bean/object includes user-specific data, and includes a number of helper methods. For example, you can obtain an iterator of the groups the user belongs to, etc.

Note: The group bean/object is essentially a user bean/object. The primary difference is that the user bean/object contains only user-specific information, and user-specific helper methods. Also, the type attribute will be 1 if a group, and 2 if a user.

Syntax

The following examples illustrate how to "get" and/or "set" various attributes of the user bean/object. Use whichever syntax feels best to you.

Loading the Bean

You can load a user bean/object by any of the following attributes:

  • userid
  • username
  • remoteid
<cfset userBean = m.getBean('user').loadBy(username='steve')>

The user bean/object's loadBy method allows for an optional second argument, labeled siteid. This is necessary when working with a user assigned to a different siteid than the site you are currently working with. For example, if you are working on "Site B" and your user was created under the "default" site, then you would have to load the user similar to the example below.

<cfset userBean = m.getBean('user').loadBy(username='steve', siteid='default')>

Once you have a variable to reference the desired bean/object, you can use the example Getters and Setters below.

Getters

userBean.get('attributeName')
userBean.get{AttributeName}()
userBean.getValue('attributeName')

Setters

userBean.set('attributeName', 'someValue')
userBean.set{AttributeName}('someValue')
userBean.setValue('attributeName', 'someValue')

Usage

Use the user bean/object to access and/or manipulate a Mura user.

Attributes

The table below lists available attributes.

Attribute Description
addresses A recordset of the user's addresses.
categoryid A comma-delimited list of CategoryIDs the user has selected as interests.
company The user's company.
created Date/time the user was created.
email The user's email address.
fname The user's first name.
inactive Whether the user/group is inactive.
interests A comma-delimited list of CategoryIDs the user has selected as interests.
isnew Whether the user bean is new.
ispublic Whether the user is a Site Member (1) or System User (0).
jobtitle The user's job title.
lastlogin Date/time the user last logged in.
lastupdate Date/time the user was last updated.
lastupdateby Name of the user who last updated the user.
lastupdatebyid UserID of the user who last updated the user.
lname The user's last name.
mobilephone The user's mobile phone number.
notes The user's notes.
password The user's encrypted password.
passwordcreated Date/time the user's password was last updated.
photofileext The file extension of the user's photo.
photofileid A unique identifier for the user's photo.
primaryaddressid The unique identifier for the user's primary address.
remoteid A special field for developer's to use. May load the user by this field. It does not have to be unique. Typically, used to store a unique identifier to associate the user to an external data store.
s2 Whether the user is a "super admin".
siteid SiteID the user belongs to.
subtype The user's subtype.
type Whether the user is a group (1) or user (2).
userid A unique identifier for the user.
username The user's username.
website The user's website address.

Helper Methods

When working with users, the following user bean/object's helper methods may be quite useful.

isInGroup('{groupName}')

Checks to see if the user is a member of a specific group.

<cfif userBean.isInGroup('admin')>
<!--- User is a member of the 'admin' group --->
<cfelse>
<!--- User is NOT a member of the 'admin' group --->
</cfif>

getFullName()

Concatenates the user's first name and last name.

<cfoutput>
#esapiEncode('html', userBean.getFullName())#
</cfoutput>

getMembershipsIterator()

Returns an iterator of the groups the user belongs to.

<cfset it = userBean.getMembershipsIterator()>
<h3>User Memberships</h3>
<!--- Loop over the iterator --->
<cfif it.hasNext()>
<ul>
<cfloop condition="it.hasNext()">
<cfset item = it.next()>
  <li>
#esapiEncode('html', item.get('groupname'))#
  </li>
  </cfloop>
  </ul>
<cfelse>
  <p>User does not belong to any groups.</p>
</cfif>

getMembershipsQuery()

Returns a recordset of the groups the user belongs to.

<cfset rsMemberships = userBean.getMembershipsQuery()>

getInterestGroupsIterator()

Returns an iterator of interest groups the user has been assigned to.

<cfset it = userBean.getInterestGroupsIterator()>
<h3>User Interests</h3>
<!--- Loop over the iterator --->
<cfif it.hasNext()>
<ul>
<cfloop condition="it.hasNext()">
<cfset item = it.next()>
  <li>
#esapiEncode('html', item.get('name'))#
  </li>
  </cfloop>
  </ul>
<cfelse>
  <p>User does not have any interests.</p>
</cfif>

getInterestGroupsQuery()

Returns a recordset of the groups the user belongs to.

<cfset rsInterestGroups = userBean.getInterestGroupsQuery()>

getAddressesIterator()

Returns an iterator of the user's addresses.

<cfset it = userBean.getAddressesIterator()>
<h3>User Addresses</h3>
<!--- Loop over the iterator --->
<cfif it.hasNext()>
<ul>
<cfloop condition="it.hasNext()">
<cfset item = it.next()>
  <li>
#esapiEncode('html', item.get('addressname'))#
  </li>
  </cfloop>
  </ul>
<cfelse>
  <p>User does not have any addresses.</p>
</cfif>

getAddressesQuery()

Returns a recordset of the user's addresses.

<cfset rsUserAddresses = userBean.getAddressesQuery()>

checkEmail('{emailAddress}')

Returns true if the email address being passed in is safe to use, meaning that it doesn't match any other user's email address. Otherwise, returns false, if the email address matches another Mura user account's email address.

<cfif userBean.checkEmail('steve@blueriver.com')>
<!--- Safe to use --->
  <cfset userBean.set('email', 'steve@blueriver.com').save()>
<cfelse>
<!--- Email address matches another user's email address --->
</cfif>

checkUsername('{username}')

Returns true if the username being passed in is safe to use, meaning that it doesn't match any other user's username. Otherwise, returns false, if the username matches another Mura user account's username.

<cfif userBean.checkUsername('steve')>
<!--- Safe to use --->
<cfset userBean.set('username', 'steve').save()>
<cfelse>
<!--- Username matches another user's username --->
</cfif>