com.stackmob.sdk.model
Class StackMobUser

java.lang.Object
  extended by com.stackmob.sdk.model.StackMobModel
      extended by com.stackmob.sdk.model.StackMobUser

public abstract class StackMobUser
extends StackMobModel

A specialized subclass of StackMobModel to represent users of your app. Extend this class with the fields you want and you have an object that knows how to do logins as well as synchronize itself with the cloud.

 public class User extends StackMobUser {

     private String email;
     private List<User> friends;
     private List<TaskList> taskLists;

     public User(String username, String password, String email) {
         super(User.class, username, password);
         this.email = email;
     }

     //Add whatever setters/getters/other functionality you want here
 }
 
 
There is a built in concept of username and password, so you shouldn't declare fields for those. You must follow the same rules for fields as you would for StackMobModel. Most likely your app will begin like this
 if(stackmob.isLoggedIn()) {
     User.getLoggedInUser(User.class, new StackMobQueryCallback<User>() {
         public void success(List<User> result) {
             startAppWithUserData(result.get(0));
         }

         public void failure(StackMobException e) {
             // handle failure
         }
     });
 } else {
     // show login screen to get credentials
     final User theUser = new User(username, password);
     theUser.login(new StackMobModelCallback() {
         public void success() {
             startAppWithUserData(theUser);
         }

         public void failure(StackMobException e) {
             // handle failure case
         }
     });
 }
 
 
After either path you've got a confirmed logged in user and their user data.


Field Summary
 
Fields inherited from class com.stackmob.sdk.model.StackMobModel
id
 
Constructor Summary
protected StackMobUser(Class<? extends StackMobUser> actualClass)
          Create a new user of the specified class.
protected StackMobUser(Class<? extends StackMobUser> actualClass, String username)
          Create a new user of the specified class with a username.
protected StackMobUser(Class<? extends StackMobUser> actualClass, String username, String password)
          Create a new user of the specified class with a username and password.
 
Method Summary
 void createWithFacebook(String facebookToken, StackMobCallback callback)
          Create this user on StackMob and associate it with an existing Facebook user via Facebook credentials.
 void createWithTwitter(String twitterToken, String twitterSecret, StackMobCallback callback)
          Create this user on StackMob and associate it with an existing Twitter user via Twitter credentials.
 void getFacebookUserInfo(StackMobRawCallback callback)
          Get Facebook user info for the current user.
 String getIDFieldName()
          Determines the field name for the primary key on the server.
static
<T extends StackMobUser>
void
getLoggedInUser(Class<T> classOfT, StackMobOptions options, StackMobQueryCallback<T> callback)
          Get the currently logged in user.
static
<T extends StackMobUser>
void
getLoggedInUser(Class<T> classOfT, StackMobQueryCallback<T> callback)
          Get the currently logged in user.
static
<T extends StackMobUser>
void
getLoggedInUser(StackMob stackmob, Class<T> classOfT, StackMobOptions options, StackMobQueryCallback<T> callback)
          Get the currently logged in user.
static String getLoggedInUsername()
          Deprecated. 
 void getPushTokens(StackMobRawCallback callback)
          Retrieve the push tokens associated with this user.
 String getSchemaName()
          The name of the schema this object corresponds to on the server.
 void getTwitterUserInfo(StackMobRawCallback callback)
          Get Twitter user info for the current user.
 String getUsername()
          Get the username, which also serves as a primary key.
 boolean isLoggedIn()
          Check if the user is logged in.
 void linkWithFacebook(String facebookToken, StackMobCallback callback)
          Link a user with an existing Facebook user via Facebook credentials.
 void linkWithTwitter(String twitterToken, String twitterSecret, StackMobCallback callback)
          Link a user with an existing Facebook user via Facebook credentials.
protected  void login(Map<String,String> args, StackMobOptions options, StackMobCallback callback)
          Log this user into StackMob with specialized info.
 void login(StackMobCallback callback)
          Log this user into StackMob.
 void login(StackMobOptions options, StackMobCallback callback)
          Log this user into StackMob.
 void loginResettingTemporaryPassword(String newPassword, StackMobCallback callback)
          Log this user into StackMob with their temporary password and reset their password.
 void loginResettingTemporaryPassword(String newPassword, StackMobOptions options, StackMobCallback callback)
          Log this user into StackMob with their temporary password and reset their password.
 void loginWithFacebook(String facebookToken, boolean createUser, String username, StackMobOptions options, StackMobCallback callback)
          Login to StackMob with Facebook credentials.
 void loginWithFacebook(String facebookToken, StackMobCallback callback)
          Login to StackMob with Facebook credentials.
 void loginWithGigya(String gigyaUid, String timestamp, String sig, StackMobOptions options, StackMobCallback callback)
          Login to StackMob with gigya credentials.
 void loginWithTwitter(String twitterToken, String twitterSecret, boolean createUser, String username, StackMobOptions options, StackMobCallback callback)
          Login to StackMob with twitter credentials.
 void loginWithTwitter(String twitterToken, String twitterSecret, StackMobCallback callback)
          Login to StackMob with twitter credentials.
 void logout(StackMobCallback callback)
          Log the user out, clearing all credential.
 void postFacebookMessage(String msg, StackMobRawCallback callback)
          Post a message to Facebook.
 void postTwitterUpdate(String message, StackMobRawCallback callback)
          Update the logged in user’s Twitter status.
static
<T extends StackMobUser>
void
pushToMultiple(Map<String,String> payload, List<T> users, StackMobRawCallback callback)
          Send a push notification to a group of users.
 void refreshLogin(StackMobCallback callback)
          Refresh the current OAuth2 login.
 boolean refreshRequired()
          Check whether a refreshLogin(com.stackmob.sdk.callback.StackMobCallback) call is required to continue making authenticated requests.
 void registerForPush(StackMobPushToken token, StackMobRawCallback callback)
          Register this user for push.
 void removeFromPush(StackMobPushToken token, StackMobRawCallback callback)
          Remove this token from push.
 void resetPassword(String oldPassword, String newPassword, StackMobCallback callback)
          Reset this user's passwords.
 void save(StackMobOptions options, StackMobCallback callback)
          Save the object to the server with options.
 void sendPush(Map<String,String> payload, StackMobRawCallback callback)
          Send a push message to this user.
static void sentForgotPasswordEmail(String username, StackMobCallback callback)
          Send out a password reset email to a user who's forgotten their password.
 void unlinkFromFacebook(StackMobCallback callback)
          Unlink a user from their Facebook credentials, if linked.
 void unlinkFromTwitter(StackMobCallback callback)
          Unlink a user from their Twitter credentials, if linked.
 
Methods inherited from class com.stackmob.sdk.model.StackMobModel
append, appendAndSave, count, count, delete, delete, destroy, destroy, exists, fetch, fetch, fillFromJson, getID, hasData, init, newFromJson, query, query, query, query, remove, removeAndDelete, save, save, save, saveMultiple, saveMultiple, setID, setStackMob, toJson, toJson, toJsonElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackMobUser

protected StackMobUser(Class<? extends StackMobUser> actualClass,
                       String username,
                       String password)
Create a new user of the specified class with a username and password.

Parameters:
actualClass - The subclass being constructed
username - The user's username
password - The user's password

StackMobUser

protected StackMobUser(Class<? extends StackMobUser> actualClass,
                       String username)
Create a new user of the specified class with a username.

Parameters:
actualClass - The subclass being constructed
username - The user's username

StackMobUser

protected StackMobUser(Class<? extends StackMobUser> actualClass)
Create a new user of the specified class.

Parameters:
actualClass - The subclass being constructed
Method Detail

save

public void save(StackMobOptions options,
                 StackMobCallback callback)
Description copied from class: StackMobModel
Save the object to the server with options. Use StackMobOptions#depthOf(int) to also save its children to the given depth.

Overrides:
save in class StackMobModel
Parameters:
options - options, such and select and expand, to apply to the request
callback - invoked when the save is complete

sentForgotPasswordEmail

public static void sentForgotPasswordEmail(String username,
                                           StackMobCallback callback)
Send out a password reset email to a user who's forgotten their password.

Parameters:
username - The user who's forgotten their password
callback - Callback to be called when the server returns. may execute in a separate thread

pushToMultiple

public static <T extends StackMobUser> void pushToMultiple(Map<String,String> payload,
                                                           List<T> users,
                                                           StackMobRawCallback callback)
Send a push notification to a group of users.

Parameters:
payload - The payload to send
callback - Callback to be called when the server returns. may execute in a separate thread

getLoggedInUser

public static <T extends StackMobUser> void getLoggedInUser(Class<T> classOfT,
                                                            StackMobQueryCallback<T> callback)
Get the currently logged in user. Use to get the user object in place of login when you're starting your app and you find that you're still logged in (via StackMob.isLoggedIn()).

Parameters:
classOfT - The class of the user model
callback - The callback to invoke with the user model

getLoggedInUser

public static <T extends StackMobUser> void getLoggedInUser(Class<T> classOfT,
                                                            StackMobOptions options,
                                                            StackMobQueryCallback<T> callback)
Get the currently logged in user. Use to get the user object in place of login when you're starting your app and you find that you're still logged in (via StackMob.isLoggedIn()).

Parameters:
classOfT - The class of the user model
options - Additional options, such as headers, to modify the request
callback - The callback to invoke with the user model

getLoggedInUser

public static <T extends StackMobUser> void getLoggedInUser(StackMob stackmob,
                                                            Class<T> classOfT,
                                                            StackMobOptions options,
                                                            StackMobQueryCallback<T> callback)
Get the currently logged in user. Use to get the user object in place of login when you're starting your app and you find that you're still logged in (via StackMob.isLoggedIn()).

Parameters:
classOfT - The class of the user model
options - Additional options, such as headers, to modify the request
callback - The callback to invoke with the user model

getLoggedInUsername

@Deprecated
public static String getLoggedInUsername()
Deprecated. 

Get the username for the logged in user, if one exists. This method is deprecated and StackMob#getLoggedInUser(com.stackmob.sdk.callback.StackMobCallback) should be used instead.

Returns:
The logged in user's username

getSchemaName

public String getSchemaName()
Description copied from class: StackMobModel
The name of the schema this object corresponds to on the server. To override, create the following static method in your sublcass: *
 public static String overrideSchemaName() {
     return "thenameyouwant";
 }
 
 
The static method is necessary for the name to be accessible from static method By default it's the name of the class in lower case. Must be less than 25 alphanumeric characters.

Overrides:
getSchemaName in class StackMobModel
Returns:
the schema name

getIDFieldName

public String getIDFieldName()
Description copied from class: StackMobModel
Determines the field name for the primary key on the server. By default it's the name of the class in lower case plus "_id". Override in subclasses to change that. Must be 3-25 alphanumeric characters

Overrides:
getIDFieldName in class StackMobModel
Returns:
the id field name

getUsername

public String getUsername()
Get the username, which also serves as a primary key.

Returns:
The username

login

protected void login(Map<String,String> args,
                     StackMobOptions options,
                     StackMobCallback callback)
Log this user into StackMob with specialized info. This will clear the password from the class.

Parameters:
args - Key/value pair arguments
options - Additional options, such as headers, to modify the request
callback - Invoked on completed login attempt

login

public void login(StackMobCallback callback)
Log this user into StackMob. This will clear the password from the class.

Parameters:
callback - Invoked on completed login attempt

login

public void login(StackMobOptions options,
                  StackMobCallback callback)
Log this user into StackMob. This will clear the password from the class.

Parameters:
options - Additional options, such as headers, to modify the request
callback - Invoked on completed login attempt

loginResettingTemporaryPassword

public void loginResettingTemporaryPassword(String newPassword,
                                            StackMobCallback callback)
Log this user into StackMob with their temporary password and reset their password. This should be used when the StackMobRawCallback.temporaryPasswordResetRequired(com.stackmob.sdk.exception.StackMobException) callback is called. This is used as part of the forgot password flow.

Parameters:
callback - Invoked on completed login attempt

loginResettingTemporaryPassword

public void loginResettingTemporaryPassword(String newPassword,
                                            StackMobOptions options,
                                            StackMobCallback callback)
Log this user into StackMob with their temporary password and reset their password. This should be used when the StackMobRawCallback.temporaryPasswordResetRequired(com.stackmob.sdk.exception.StackMobException) callback is called. This is used as part of the forgot password flow.

Parameters:
options - Additional options, such as headers, to modify the request
callback - Invoked on completed login attempt

loginWithFacebook

public void loginWithFacebook(String facebookToken,
                              StackMobCallback callback)
Login to StackMob with Facebook credentials. The credentials should match an existing user object that has a linked Facebook account, via either createWithFacebook(String, com.stackmob.sdk.callback.StackMobCallback) or linkWithFacebook(String, com.stackmob.sdk.callback.StackMobCallback).

Parameters:
facebookToken - The facebook user token
callback - Callback to be called when the server returns. may execute in a separate thread

loginWithFacebook

public void loginWithFacebook(String facebookToken,
                              boolean createUser,
                              String username,
                              StackMobOptions options,
                              StackMobCallback callback)
Login to StackMob with Facebook credentials. The method includes the option to create a StackMob user if one didn't exist before. Otherwise, the credentials should match an existing user object that has a linked Facebook account, via either createWithFacebook(String, com.stackmob.sdk.callback.StackMobCallback) or linkWithFacebook(String, com.stackmob.sdk.callback.StackMobCallback).

Parameters:
facebookToken - The facebook user token
createUser - Pass true to create a new user if no existing user is associated with the provided token. This works with OAuth2 only.
username - If createUser is true, the primary key (username) to give the created user.
options - Additional options, such as headers, to modify the request
callback - Callback to be called when the server returns. may execute in a separate thread

loginWithTwitter

public void loginWithTwitter(String twitterToken,
                             String twitterSecret,
                             StackMobCallback callback)
Login to StackMob with twitter credentials. The credentials should match an existing user object that has a linked Twitter account, via either createWithTwitter(String, String, com.stackmob.sdk.callback.StackMobCallback) or linkWithTwitter(String, String, com.stackmob.sdk.callback.StackMobCallback).

Parameters:
twitterToken - The twitter session key (this is a per user key - different from the consumer key)
twitterSecret - The twitter session secret (this is a per user secret - different from the consumer secret)
callback - Callback to be called when the server returns. may execute in a separate thread

loginWithTwitter

public void loginWithTwitter(String twitterToken,
                             String twitterSecret,
                             boolean createUser,
                             String username,
                             StackMobOptions options,
                             StackMobCallback callback)
Login to StackMob with twitter credentials. The method includes the option to create a StackMob user if one didn't exist before. Otherwise, the credentials should match an existing user object that has a linked Twitter account, via either createWithTwitter(String, String, com.stackmob.sdk.callback.StackMobCallback) or linkWithTwitter(String, String, com.stackmob.sdk.callback.StackMobCallback).

Parameters:
twitterToken - The twitter session key (this is a per user key - different from the consumer key)
twitterSecret - The twitter session secret (this is a per user secret - different from the consumer secret)
createUser - Pass true to create a new user if no existing user is associated with the provided tokens. This works with OAuth2 only.
username - If createUser is true, the primary key (username) to give the created user.
options - Additional options, such as headers, to modify the request
callback - Callback to be called when the server returns. may execute in a separate thread

loginWithGigya

public void loginWithGigya(String gigyaUid,
                           String timestamp,
                           String sig,
                           StackMobOptions options,
                           StackMobCallback callback)
Login to StackMob with gigya credentials. If a corresponding StackMob user didn't exist before, it will be created.

Parameters:
gigyaUid - The parameter UID
timestamp - The parameter signatureTimestamp
sig - The parameter UIDSignature
options - Additional options, such as headers, to modify the request
callback - Callback to be called when the server returns. may execute in a separate thread

refreshLogin

public void refreshLogin(StackMobCallback callback)
Refresh the current OAuth2 login. This ordinarily happens automatically, but this method can give you finer control if you need it. Logins last an hour by default. Once they expire they need to be refreshed. Make sure not to send multiple refresh token requests.

Parameters:
callback - Callback to be called when the server returns. may execute in a separate thread

logout

public void logout(StackMobCallback callback)
Log the user out, clearing all credential.

Parameters:
callback - invoked when logout is complete

isLoggedIn

public boolean isLoggedIn()
Check if the user is logged in.

Returns:
whether the user is logged in

refreshRequired

public boolean refreshRequired()
Check whether a refreshLogin(com.stackmob.sdk.callback.StackMobCallback) call is required to continue making authenticated requests. This will happen automatically, so there's no reason to check this method unless you're overriding the existing refresh token system. If there are no credentials at all this will be false.

Returns:
Whether there's a valid refresh token that can be used to refresh the login

createWithFacebook

public void createWithFacebook(String facebookToken,
                               StackMobCallback callback)
Create this user on StackMob and associate it with an existing Facebook user via Facebook credentials.

Parameters:
facebookToken - The facebook user token
callback - Callback to be called when the server returns. may execute in a separate thread

createWithTwitter

public void createWithTwitter(String twitterToken,
                              String twitterSecret,
                              StackMobCallback callback)
Create this user on StackMob and associate it with an existing Twitter user via Twitter credentials.

Parameters:
twitterToken - The twitter session key (this is a per user key - different from the consumer key)
twitterSecret - The twitter session secret (this is a per user secret - different from the consumer secret)
callback - Callback to be called when the server returns. May execute in a separate thread

linkWithFacebook

public void linkWithFacebook(String facebookToken,
                             StackMobCallback callback)
Link a user with an existing Facebook user via Facebook credentials. The user must be logged in.

Parameters:
facebookToken - The Facebook user token
callback - Callback to be called when the server returns. may execute in a separate thread

unlinkFromFacebook

public void unlinkFromFacebook(StackMobCallback callback)
Unlink a user from their Facebook credentials, if linked. The user must be logged in.

Parameters:
callback - Callback to be called when the server returns. May execute in a separate thread.

linkWithTwitter

public void linkWithTwitter(String twitterToken,
                            String twitterSecret,
                            StackMobCallback callback)
Link a user with an existing Facebook user via Facebook credentials. The user must be logged in.

Parameters:
twitterToken - The twitter session key (this is a per user key - different from the consumer key)
twitterSecret - The twitter session secret (this is a per user secret - different from the consumer secret)
callback - Callback to be called when the server returns. may execute in a separate thread

unlinkFromTwitter

public void unlinkFromTwitter(StackMobCallback callback)
Unlink a user from their Twitter credentials, if linked. The user must be logged in.

Parameters:
callback - Callback to be called when the server returns. May execute in a separate thread.

postFacebookMessage

public void postFacebookMessage(String msg,
                                StackMobRawCallback callback)
Post a message to Facebook. This method will not post to FB and will return nothing if there is no user logged into FB.

Parameters:
msg - The message to post
callback - Callback to be called when the server returns. may execute in a separate thread

postTwitterUpdate

public void postTwitterUpdate(String message,
                              StackMobRawCallback callback)
Update the logged in user’s Twitter status. The logged in user must have a linked Twitter account.

Parameters:
message - The message to send. must be <= 140 characters
callback - Callback to be called when the server returns. may execute in a separate thread

getFacebookUserInfo

public void getFacebookUserInfo(StackMobRawCallback callback)
Get Facebook user info for the current user. This method will return nothing if there is no currently logged in FB user.

Parameters:
callback - Callback to be called when the server returns. may execute in a separate thread

getTwitterUserInfo

public void getTwitterUserInfo(StackMobRawCallback callback)
Get Twitter user info for the current user. This method will return nothing if there is no currently logged in Twitter user.

Parameters:
callback - Callback to be called when the server returns. May execute in a separate thread

resetPassword

public void resetPassword(String oldPassword,
                          String newPassword,
                          StackMobCallback callback)
Reset this user's passwords. Passwords cannot be changed directly when saving objects.

Parameters:
oldPassword - The users' old password
newPassword - The new password
callback - Invoked upon completed reset

registerForPush

public void registerForPush(StackMobPushToken token,
                            StackMobRawCallback callback)
Register this user for push.

Parameters:
token - The Android registration id to associate with this user
callback - Invoked when the operation is complete

sendPush

public void sendPush(Map<String,String> payload,
                     StackMobRawCallback callback)
Send a push message to this user.

Parameters:
payload - The message to send
callback - Invoked when the operation is complete

removeFromPush

public void removeFromPush(StackMobPushToken token,
                           StackMobRawCallback callback)
Remove this token from push.

Parameters:
token - The token to remove
callback - Invoked when the operation is complete

getPushTokens

public void getPushTokens(StackMobRawCallback callback)
Retrieve the push tokens associated with this user.

Parameters:
callback - Invoked when the operation is complete


Copyright © 2013 StackMob. All Rights Reserved.