UserManager

Handles the identity of the local user:

This class is instantiated by FlockEngine, you can ccess the methods via Flock.User.isAuthenticated(), etc.


Summary

Nested Class Summary
static interface UserManager.UserAttributesCallback
          Callback to be invoked after retrieving the attributes of the current user with retrieveAttributes()
 
Field Summary
 Facebook Facebook
          Implementation of the official Facebook API for Android.
 
Method Summary
 boolean authenticate(java.lang.String username, java.lang.String password)
          Authenticate the local user with the given credentials, if not an anonymous session.
 void authenticateWithFacebook(java.lang.String app_id)
          Instead of using your private user database at the Flock servers, you can open a Facebook authentication dialog with this function.
 void authenticateWithFacebook(java.lang.String app_id, java.lang.String username_preset)
           
 void authenticateWithGUI()
          GUI Interface for Login
 void authenticateWithGUI(java.lang.String username_preset)
          GUI Interface for Login with preset username
 boolean createAccount(java.lang.String username, java.lang.String password, java.lang.String email)
          Create a new user account in the background (if not anonymous session).
 void createAccountWithGUI()
          GUI Interface for Registration (with email field)
 void createAccountWithGUI(boolean display_email_field)
          GUI Interface for Registration (with option to remove email input)
 void createAccountWithGUI(boolean display_email_field, java.lang.String username_preset)
          GUI Interface for Registration (with option to remove email input and with preset username)
 java.lang.String getUsername()
          Returns currently set username.
 boolean isAuthenticated()
          Returns true if user credentials are authenticated
 boolean retrieveAttributes(UserManager.UserAttributesCallback cb)
          Rretrieve all attributes of the local (authenticated) user outside of a game.
 void setPasswordMinLength(int minlength)
          Sets a minimum length for the password for non-anonymous games.
 void setUsername(java.lang.String username)
          Set a username for the local user (only used for anonymous games).
 void setUsernameBlacklist(java.util.List<java.lang.String> blacklist)
          Set a blacklist of terms which cannot be used inside a username (case insensitive).
 void setUsernameBlacklist(java.lang.String[] blacklist)
          Set a blacklist of terms which cannot be used inside a username (case insensitive).
 void setUsernameMaxLength(int maxlength)
          Sets a maximum length for the username (especially if you want to use the GUI).
 void setUsernameMinLength(int minlength)
          Sets a minimum length for the username (especially if you want to use the GUI).
 void signOut()
          Sign the local user out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Details

Field Detail

Facebook

public Facebook Facebook
Implementation of the official Facebook API for Android. You can use it after a user signed in via authenticateWithFacebook(app_id).

See Also:
authenticateWithFacebook(String)
Method Detail

signOut

public void signOut()
Sign the local user out. Happens immediately - no network connection necessary and no event will be received.


getUsername

public java.lang.String getUsername()
Returns currently set username.

Returns:
last username set by setUsername() or authenticate() or createAccount(). Does not mean user is authenticated.
See Also:
isAuthenticated()

isAuthenticated

public boolean isAuthenticated()
Returns true if user credentials are authenticated

Returns:
True if user has successfully authenticated with the current credentials, or setAnonymousSession was set to true and username.length > username_minlength.

setUsernameMinLength

public void setUsernameMinLength(int minlength)
Sets a minimum length for the username (especially if you want to use the GUI). Default: 3.

Parameters:
minlength - minimum amount of characters

setUsernameMaxLength

public void setUsernameMaxLength(int maxlength)
Sets a maximum length for the username (especially if you want to use the GUI). Default: 12.

Parameters:
minlength - minimum amount of characters

setPasswordMinLength

public void setPasswordMinLength(int minlength)
Sets a minimum length for the password for non-anonymous games. Set before createAccountWithGUI() or authenticateWithGUI(). Default: 3.

Parameters:
minlength - minimum amount of characters

setUsername

public void setUsername(java.lang.String username)

Set a username for the local user (only used for anonymous games). Anonymous users are not authenticated other than having a valid username. (A valid username contains at least the number of chars set by setUsernameMinLength()

If no anonymous session, always use authenticate() or createAccount() to set an authenticated username.

Parameters:
username -

createAccount

public boolean createAccount(java.lang.String username,
                             java.lang.String password,
                             java.lang.String email)
                      throws UsernameBlacklistedException
Create a new user account in the background (if not anonymous session). Email is optional.
  1. Checks username, password and email, and returns false if invalid (too short)
  2. Logs any current user out
  3. Starts registration in the background
  4. If registration succeeds, new user will be logged in

If anonymous session, there is no need to use this because all usernames are successfully authenticated and a user cannot permanently register an account.

Happens in the background. Possible responses via MultiplayerStatusListener:
  1. CREATEACCOUNT_FAILED ......... Technical problem on server side
  2. CREATEACCOUNT_USERNAMETAKEN .. Username already taken
  3. CREATEACCOUNT_SUCCESS ........ Account successfully created (always followed by STATUS_AUTH_SUCCESS)
  4. AUTH_SUCCESS ................. User authentication successful

Parameters:
username - Username to create account for (all white space characters from beginning and end will be removed with trim())
password -
email - optional an email to submit for creating the account. If length > 0 then checked for '@' and '.'
Returns:
true if registration at server started in bg, false if anonymous session or username too short or long, or password too short or email invalid
Throws:
UsernameBlacklistedException
See Also:
createAccountWithGUI()

authenticate

public boolean authenticate(java.lang.String username,
                            java.lang.String password)
Authenticate the local user with the given credentials, if not an anonymous session.

If anonymous session: Activity will immediately receive FlockEvent.AUTH_SUCCESS. All usernames are accepted (without pwd check).

Happens in the background. Possible responses via MultiplayerStatusListener:

  1. AUTH_FAILED .......... Technical problem on server side
  2. AUTH_REJECTED ........ Username/Password combination invalid
  3. AUTH_SUCCESS ......... User authentication successful

Parameters:
username - All whitespace characters around username will be removed by trim()
password -
Returns:
true if authenticating at server in bg, false if anonymous session or too short username or too short password
See Also:
authenticateWithGUI()

authenticateWithGUI

public void authenticateWithGUI()
GUI Interface for Login


authenticateWithGUI

public void authenticateWithGUI(java.lang.String username_preset)
GUI Interface for Login with preset username


createAccountWithGUI

public void createAccountWithGUI()
GUI Interface for Registration (with email field)


createAccountWithGUI

public void createAccountWithGUI(boolean display_email_field)
GUI Interface for Registration (with option to remove email input)


createAccountWithGUI

public void createAccountWithGUI(boolean display_email_field,
                                 java.lang.String username_preset)
GUI Interface for Registration (with option to remove email input and with preset username)


authenticateWithFacebook

public void authenticateWithFacebook(java.lang.String app_id)
Instead of using your private user database at the Flock servers, you can open a Facebook authentication dialog with this function. You can register your app here: http://developers.facebook.com/setup/ (be sure to format your url like this: http://flockengine.com/ (no www., with trailing slash))

Parameters:
app_id - Your facebook app-id
See Also:
Facebook

authenticateWithFacebook

public void authenticateWithFacebook(java.lang.String app_id,
                                     java.lang.String username_preset)

retrieveAttributes

public boolean retrieveAttributes(UserManager.UserAttributesCallback cb)

Rretrieve all attributes of the local (authenticated) user outside of a game.

Runs in the background; if finished the specified callback is started. Callback may receive an empty Map if no attributes were previously saved (eg. no games played)

Returns:
true if request in progress, false if anonymous game or user not authenticated

setUsernameBlacklist

public void setUsernameBlacklist(java.lang.String[] blacklist)
Set a blacklist of terms which cannot be used inside a username (case insensitive). Each term in the blacklist is searched for in the username.


setUsernameBlacklist

public void setUsernameBlacklist(java.util.List<java.lang.String> blacklist)
Set a blacklist of terms which cannot be used inside a username (case insensitive). Each term in the blacklist is searched for in the username.