Packagenet.user1.reactor
Classpublic class UserAccount
InheritanceUserAccount Inheritance flash.events.EventDispatcher

Since : Reactor 1.0.0

The UserAccount class represents a Union user account. Each user account can save information in persistent attributes, which are stored in a server-side database or other custom datasource. User accounts are created with the AccountManager class's createAccount() method. Clients login to user accounts via the AccountManager class's login() method. When a client logs in, its Client object is linked with a UserAccount object. To access the account's events and data, use the Client class's getAccount() method, which returns a UserAccount object.

When a client logs into an account, that account's global attributes are loaded automatically, and are immediately available via UserAccount's getAttribute() method. Account attributes scoped to a room are loaded automatically when the logged-in client joins or observes that room.

To access the list of UserAccount objects known to the current client, use the AccountManager class's getAccounts() method.

The following code demonstrates how to create a user account, login to that account, and then set a persistent account attribute. For an overview of user accounts in Reactor, see AccountManager class.

   package {
     import flash.display.Sprite;
        import net.user1.reactor.Reactor;
     import net.user1.reactor.ReactorEvent;
     
     public class AccountExample extends Sprite {
       protected var reactor:Reactor;
    
       public function AccountExample () {
         reactor = new Reactor();
         reactor.addEventListener(ReactorEvent.READY, readyListener);
         reactor.connect("tryunion.com", 80);
       }
   
       protected function readyListener (e:ReactorEvent):void {
         // Create a user account with the userID "bob"
         reactor.getAccountManager().createAccount("bob", "secretpassword");
         // Register to be notified when a user logs in
         reactor.getAccountManager().addEventListener(AccountEvent.LOGIN, loginListener);
         // Log the current client into "bob"'s user account
         reactor.getAccountManager().login("bob", "secretpassword");
       }
   
       protected function loginListener (e:AccountEvent):void {
         // When the current client logs in...
         if (e.getAccount().isSelf()) {
           // ...save an attribute named "age" in bob's user account
           e.getAccount().setAttribute("age", "39");
         }
       }
     }
   }
   

See also

Client.getAccount()
AccountManager.getAccounts()
AccountManager
AccountEvent


Public Methods
 MethodDefined By
  
UserAccount(userID:String, log:Logger, accountManager:AccountManager, clientManager:ClientManager, roomManager:RoomManager)
Constructor.
UserAccount
  
addRole(role:String):void
Adds a new security role to the account.
UserAccount
  
changePassword(newPassword:String, oldPassword:String):void
Changes the account's password.
UserAccount
  
deleteAttribute(attrName:String, attrScope:String = null):void
Deletes an attribute from this user account.
UserAccount
  
getAttribute(attrName:String, attrScope:String = null):String
Retrieves a persistent client attribute.
UserAccount
  
getAttributes():Object
Returns an object containing all attributes for this user account.
UserAccount
  
getAttributesByScope(scope:String = null):Object
Returns an object containing the names and values of all attributes defined on this UserAccount instance for a given scope, or for all scopes.
UserAccount
  
Returns a reference to this account's Client object, which is available if this account is logged in only.
UserAccount
  
Indicates whether this UserAccount is currently logged in.
UserAccount
  
Returns the internal Client object for this account's corresponding client.
UserAccount
  
getUserID():String
Returns this account's userID.
UserAccount
  
isLoggedIn():Boolean
Returns true if this user account's connection state is ConnectionState.LOGGED_IN; false otherwise.
UserAccount
  
isModerator():Boolean
Returns a Boolean indicating whether the account has moderator privileges.
UserAccount
  
isSelf():Boolean
Returns true if the current client is logged in under this UserAccount.
UserAccount
  
logoff(password:String = null):void
Logs off this user account.
UserAccount
  
observe():void
Asks the server to notify the current client any time this UserAccount's state changes.
UserAccount
  
removeRole(userID:String, role:String):void
Removes a security role from the account.
UserAccount
  
setAttribute(attrName:String, attrValue:String, attrScope:String = null, isShared:Boolean = true, evaluate:Boolean = false):void
Assigns an account attribute that is stored persistently on the server under this user account.
UserAccount
  
Asks the server to stop observing this UserAccount.
UserAccount
  
toString():String
[override] Provides a string representation of this object.
UserAccount
Events
 Event Summary Defined By
   Dispatched when the result of an earlier UserAccount.addRole() or AccountManager.addRole() request is received.UserAccount
   Dispatched when the current client's account password changes.UserAccount
   Dispatched when the current client receives the result of an earlier request to change a user account's password.UserAccount
   Dispatched when any client that is known to the current client logs in.UserAccount
   Dispatched when any user account that is known to the current client logs off.UserAccount
   Dispatched when the current client receives the result of an earlier request to logoff a client.UserAccount
   Dispatched when the current client observes a user account.UserAccount
   Dispatched when the result of an earlier UserAccount.observe() or AccountManager.observeAccount() request is received.UserAccount
   Dispatched when the result of an earlier UserAccount.removeRole() or AccountManager.removeRole() request is received.UserAccount
   Dispatched when the current client stops observing a user account.UserAccount
   Dispatched when the result of an earlier UserAccount.stopObserving() or AccountManager.stopObservingAccount() request is received.UserAccount
   Dispatched when a user account has been synchronized to match the state of the server.UserAccount
Constructor Description
UserAccount()Constructor
public function UserAccount(userID:String, log:Logger, accountManager:AccountManager, clientManager:ClientManager, roomManager:RoomManager)

Constructor. Developers need not invoke the UserAccount constructor directly; Reactor automatically creates UserAccount objects when clients login.

Parameters
userID:String
 
log:Logger
 
accountManager:AccountManager
 
clientManager:ClientManager
 
roomManager:RoomManager
Method Descriptions
addRole()method
public function addRole(role:String):void

Since : Reactor 1.0.0

Adds a new security role to the account.

Parameters

role:String — The desired new role. For a list of built-in security roles, see the SecurityRole class.

See also

changePassword()method 
public function changePassword(newPassword:String, oldPassword:String):void

Since : Reactor 1.0.0

Changes the account's password.

Parameters

newPassword:String — The desired new account password. Must not be null.
 
oldPassword:String — The current account password. If no password is supplied, the password will be changed if the client requesting the change has sufficient privileges only.

See also

deleteAttribute()method 
public function deleteAttribute(attrName:String, attrScope:String = null):void

Since : Reactor 1.0.0

Deletes an attribute from this user account. For general details on deleting attributes, see the Client class's deleteAttribute() method.

Parameters

attrName:String
 
attrScope:String (default = null)

See also

getAttribute()method 
public function getAttribute(attrName:String, attrScope:String = null):String

Since : Reactor 1.0.0

Retrieves a persistent client attribute. This UserAccount's persistent attributes are available only when this UserAccount is synchronized with the state of the server. To synchronize an account, the current client must do one of the following:

For general details on retrieving attributes, see the Client class's getAttribute() method.

Parameters

attrName:String
 
attrScope:String (default = null)

Returns
String

See also

getAttributes()method 
public function getAttributes():Object

Since : Reactor 1.0.0

Returns an object containing all attributes for this user account. The object's structure matches that of the analogous Client method, getAttributes(). See that method for details.

Returns
Object

See also

getAttributesByScope()method 
public function getAttributesByScope(scope:String = null):Object

Since : Reactor 1.0.0

Returns an object containing the names and values of all attributes defined on this UserAccount instance for a given scope, or for all scopes. The object's structure matches that of the analogous Client method, getAttributesByScope(). See that method for details.

Parameters

scope:String (default = null)

Returns
Object

See also

getClient()method 
public function getClient():IClient

Since : Reactor 1.0.0

Returns a reference to this account's Client object, which is available if this account is logged in only.

Returns
IClient

See also

getConnectionState()method 
public function getConnectionState():int

Since : Reactor 1.0.0

Indicates whether this UserAccount is currently logged in.

Returns
int — An integer corresponding to one of the following three constants: ConnectionState.LOGGED_IN, ConnectionState.NOT_CONNECTED, or ConnectionState.UNKNOWN.
getInternalClient()method 
public function getInternalClient():Client

Since : Reactor 1.0.0

Returns the internal Client object for this account's corresponding client. This method is required when an application wishes to access the composed Client object reference for a client with a custom client class. For details, see the ClientManager class's getInternalClient() method.

Returns
Client

See also

getUserID()method 
public function getUserID():String

Since : Reactor 1.0.0

Returns this account's userID.

Returns
String

See also

isLoggedIn()method 
public function isLoggedIn():Boolean

Since : Reactor 1.0.0

Returns true if this user account's connection state is ConnectionState.LOGGED_IN; false otherwise.

Returns
Boolean
isModerator()method 
public function isModerator():Boolean

Since : Reactor 1.0.0

Returns a Boolean indicating whether the account has moderator privileges. To assign moderator privileges to an account, use addRole().

Returns
Boolean — true if the account has moderator privileges, false otherwise.

See also

isSelf()method 
public function isSelf():Boolean

Since : Reactor 1.0.0

Returns true if the current client is logged in under this UserAccount.

Returns
Boolean

See also

logoff()method 
public function logoff(password:String = null):void

Since : Reactor 1.0.0

Logs off this user account. The result of the attempt is returned via an AccountEvent.LOGOFF_RESULT event. If the attempt succeeds, the UserAccount object triggers an AccountEvent.LOGOFF event and the corresponding client is then automatically disconnected by Union Server.

Parameters

password:String (default = null) — The account's password. If no password is supplied, the account will be logged off if the client requesting the logoff has sufficient privileges only.

See also

observe()method 
public function observe():void

Since : Reactor 1.0.0

Asks the server to notify the current client any time this UserAccount's state changes. For complete details, see the AccountManager's observeAccount() method.

See also

removeRole()method 
public function removeRole(userID:String, role:String):void

Since : Reactor 1.0.0

Removes a security role from the account.

Parameters

userID:String — The desired new role. For a list of built-in security roles, see the SecurityRole class.
 
role:String

See also

setAttribute()method 
public function setAttribute(attrName:String, attrValue:String, attrScope:String = null, isShared:Boolean = true, evaluate:Boolean = false):void

Since : Reactor 1.0.0

Assigns an account attribute that is stored persistently on the server under this user account.

Note that a logged-in client's attribute names do not conflict with its account attribute names. For example, a client might define an attribute "score" on itself and also on its user account. The two attributes are considered separate; each can have its own value.

For general details on assigning attributes, see the Client class's setAttribute() method.

Parameters

attrName:String
 
attrValue:String
 
attrScope:String (default = null)
 
isShared:Boolean (default = true)
 
evaluate:Boolean (default = false)

See also

stopObserving()method 
public function stopObserving():void

Since : Reactor 1.0.0

Asks the server to stop observing this UserAccount. As a result, the server will no longer send notifications when the UserAccount's state changes.

Results of a stopObserving() call are returned via a AccountEvent.STOP_OBSERVING_RESULT event. If the call succeeds, the AccountEvent.STOP_OBSERVING event is also triggered.

See also

toString()method 
override public function toString():String

Since : Reactor 1.0.0

Provides a string representation of this object.

Returns
String
Event Detail
ADD_ROLE_RESULT Event
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.ADD_ROLE_RESULT

Dispatched when the result of an earlier UserAccount.addRole() or AccountManager.addRole() request is received.

See also

CHANGE_PASSWORD Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.CHANGE_PASSWORD

Dispatched when the current client's account password changes. A user can change its own password via the AccountManager's changePassword() method or the UserAccount object's changePassword() method. With sufficient privileges, the current client can change another user's password. Server-side code can change any user's password.

See also

CHANGE_PASSWORD_RESULT Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.CHANGE_PASSWORD_RESULT

Dispatched when the current client receives the result of an earlier request to change a user account's password. To determine the result of the change-password request, use getStatus(), which has the following possible return values:

See also

LOGIN Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.LOGIN

Dispatched when any client that is known to the current client logs in. For a list of the situations in which a client becomes known to the current client, see the ClientManager's clientIsKnown() method. Note however, that the current client can opt out of login notification for room occupants and room observers by disabling "occupant-login-logoff updates" and "observer-login-logoff updates" via the Room class's setUpdateLevels() method.

The AccountEvent.LOGIN event is dispatched via the Client object for the client that logged in, then the UserAccount object for the logged-in account, then the AccountManager.

See also

LOGOFF Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.LOGOFF

Dispatched when any user account that is known to the current client logs off. For a list of the situations in which a client becomes known to the current client, see the ClientManager's clientIsKnown() method. Note however, that the current client can opt out of logoff notification for room occupants and room observers by disabling "occupant-login-logoff updates" and "observer-login-logoff updates" via the Room class's setUpdateLevels() method.

The AccountEvent.LOGOFF event is dispatched via the Client object for the client that logged off, then the UserAccount object for the logged-off account, then the AccountManager.

See also

LOGOFF_RESULT Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.LOGOFF_RESULT

Dispatched when the current client receives the result of an earlier request to logoff a client. To determine the result of the logoff request, use getStatus(), which has the following possible return values:

See also

OBSERVE Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.OBSERVE

Dispatched when the current client observes a user account. For complete details, see the AccountManager's observeAccount() method.

See also

OBSERVE_RESULT Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.OBSERVE_RESULT

Dispatched when the result of an earlier UserAccount.observe() or AccountManager.observeAccount() request is received.

See also

REMOVE_ROLE_RESULT Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.REMOVE_ROLE_RESULT

Dispatched when the result of an earlier UserAccount.removeRole() or AccountManager.removeRole() request is received.

See also

STOP_OBSERVING Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.STOP_OBSERVING

Dispatched when the current client stops observing a user account.

See also

STOP_OBSERVING_RESULT Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.STOP_OBSERVING_RESULT

Dispatched when the result of an earlier UserAccount.stopObserving() or AccountManager.stopObservingAccount() request is received.

See also

SYNCHRONIZE Event  
Event Object Type: AccountEvent
AccountEvent.type variable = net.user1.reactor.AccountEvent.SYNCHRONIZE

Dispatched when a user account has been synchronized to match the state of the server.

See also