Class ParseUser
- java.lang.Object
-
- com.parse.ParseObject
-
- com.parse.ParseUser
-
@ParseClassName("_User") public class ParseUser extends ParseObject
TheParseUseris a local representation of user data that can be saved and retrieved from the Parse cloud.
-
-
Field Summary
-
Fields inherited from class com.parse.ParseObject
CREATOR, DEFAULT_PIN, KEY_CREATED_AT, KEY_OBJECT_ID, KEY_UPDATED_AT
-
-
Constructor Summary
Constructors Constructor Description ParseUser()Constructs a new ParseUser with no data in it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ParseUserbecome(java.lang.String sessionToken)Authorize a user with a session token.static <any>becomeInBackground(java.lang.String sessionToken)Authorize a user with a session token.static voidbecomeInBackground(java.lang.String sessionToken, LogInCallback callback)Authorize a user with a session token.static voidenableAutomaticUser()Enables automatic creation of anonymous users.static <any>enableRevocableSessionInBackground()Enables revocable sessions.ParseUserfetch()Fetches this object with the data from the server.ParseUserfetchIfNeeded()If thisParseObjecthas not been fetched (i.e.static java.lang.StringgetCurrentSessionToken()static <any>getCurrentSessionTokenAsync()static ParseUsergetCurrentUser()This retrieves the currently logged in ParseUser with a valid session, either from memory or disk if necessary.java.lang.StringgetEmail()Retrieves the email address.static ParseQuery<ParseUser>getQuery()Constructs a query forParseUser.java.lang.StringgetSessionToken()java.lang.StringgetUsername()Retrieves the username.booleanisAuthenticated()Whether the ParseUser has been authenticated on this device.booleanisLinked(java.lang.String authType)Indicates whether this user is linked with a third party authentication source.booleanisNew()Indicates whether thisParseUserwas created during this session through a call tosignUp()or by logging in with a linked service such as Facebook.<any>linkWithInBackground(java.lang.String authType, java.util.Map<java.lang.String,java.lang.String> authData)Links this user to a third party authentication source.static ParseUserlogIn(java.lang.String username, java.lang.String password)Logs in a user with a username and password.static <any>logInInBackground(java.lang.String username, java.lang.String password)Logs in a user with a username and password.static voidlogInInBackground(java.lang.String username, java.lang.String password, LogInCallback callback)Logs in a user with a username and password.static <any>logInWithInBackground(java.lang.String authType, java.util.Map<java.lang.String,java.lang.String> authData)Logs in a user with third party authentication credentials.static voidlogOut()Logs out the currently logged in user session.static <any>logOutInBackground()Logs out the currently logged in user session.static voidlogOutInBackground(LogOutCallback callback)Logs out the currently logged in user session.voidput(java.lang.String key, java.lang.Object value)Add a key-value pair to this object.static voidregisterAuthenticationCallback(java.lang.String authType, AuthenticationCallback callback)Registers a third party authentication callback.voidremove(java.lang.String key)Removes a key from this object's data if it exists.static voidrequestPasswordReset(java.lang.String email)Requests a password reset email to be sent to the specified email address associated with the user account.static <any>requestPasswordResetInBackground(java.lang.String email)Requests a password reset email to be sent in a background thread to the specified email address associated with the user account.static voidrequestPasswordResetInBackground(java.lang.String email, RequestPasswordResetCallback callback)Requests a password reset email to be sent in a background thread to the specified email address associated with the user account.voidsetEmail(java.lang.String email)Sets the email address.voidsetPassword(java.lang.String password)Sets the password.voidsetUsername(java.lang.String username)Sets the username.voidsignUp()Signs up a new user.<any>signUpInBackground()Signs up a new user.voidsignUpInBackground(SignUpCallback callback)Signs up a new user.<any>unlinkFromInBackground(java.lang.String authType)Unlinks this user from a third party authentication source.-
Methods inherited from class com.parse.ParseObject
add, addAll, addAllUnique, addUnique, containsKey, create, create, createWithoutData, createWithoutData, delete, deleteAll, deleteAllInBackground, deleteAllInBackground, deleteEventually, deleteEventually, deleteInBackground, deleteInBackground, describeContents, fetchAll, fetchAllIfNeeded, fetchAllIfNeededInBackground, fetchAllIfNeededInBackground, fetchAllInBackground, fetchAllInBackground, fetchFromLocalDatastore, fetchFromLocalDatastoreInBackground, fetchIfNeededInBackground, fetchIfNeededInBackground, fetchInBackground, fetchInBackground, fromJSON, fromJSON, get, getACL, getBoolean, getBytes, getClassName, getCreatedAt, getDate, getDouble, getInt, getJSONArray, getJSONObject, getList, getLong, getMap, getNumber, getObjectId, getParseFile, getParseGeoPoint, getParseObject, getParsePolygon, getParseUser, getRelation, getString, getUpdatedAt, has, hasSameId, increment, increment, isDataAvailable, isDataAvailable, isDirty, isDirty, keySet, pin, pin, pinAll, pinAll, pinAllInBackground, pinAllInBackground, pinAllInBackground, pinAllInBackground, pinInBackground, pinInBackground, pinInBackground, pinInBackground, registerSubclass, removeAll, revert, revert, save, saveAll, saveAllInBackground, saveAllInBackground, saveEventually, saveEventually, saveInBackground, saveInBackground, setACL, setObjectId, unpin, unpin, unpinAll, unpinAll, unpinAll, unpinAll, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinAllInBackground, unpinInBackground, unpinInBackground, unpinInBackground, unpinInBackground, writeToParcel
-
-
-
-
Constructor Detail
-
ParseUser
public ParseUser()
Constructs a new ParseUser with no data in it. A ParseUser constructed in this way will not have an objectId and will not persist to the database untilsignUp()is called.
-
-
Method Detail
-
getQuery
public static ParseQuery<ParseUser> getQuery()
Constructs a query forParseUser.- See Also:
ParseQuery.getQuery(Class)
-
logInInBackground
public static <any> logInInBackground(java.lang.String username, java.lang.String password)Logs in a user with a username and password. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().This is preferable to using
logIn(java.lang.String, java.lang.String), unless your code is already running from a background thread.- Parameters:
username- The username to log in with.password- The password to log in with.- Returns:
- A Task that is resolved when logging in completes.
-
logIn
public static ParseUser logIn(java.lang.String username, java.lang.String password) throws ParseException
Logs in a user with a username and password. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().Typically, you should use
logInInBackground(java.lang.String, java.lang.String)instead of this, unless you are managing your own threading.- Parameters:
username- The username to log in with.password- The password to log in with.- Returns:
- The user if the login was successful.
- Throws:
ParseException- Throws an exception if the login was unsuccessful.
-
logInInBackground
public static void logInInBackground(java.lang.String username, java.lang.String password, LogInCallback callback)Logs in a user with a username and password. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().This is preferable to using
logIn(java.lang.String, java.lang.String), unless your code is already running from a background thread.- Parameters:
username- The username to log in with.password- The password to log in with.callback- callback.done(user, e) is called when the login completes.
-
becomeInBackground
public static <any> becomeInBackground(java.lang.String sessionToken)
Authorize a user with a session token. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().This is preferable to using
become(java.lang.String), unless your code is already running from a background thread.- Parameters:
sessionToken- The session token to authorize with.- Returns:
- A Task that is resolved when authorization completes.
-
become
public static ParseUser become(java.lang.String sessionToken) throws ParseException
Authorize a user with a session token. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().Typically, you should use
becomeInBackground(java.lang.String)instead of this, unless you are managing your own threading.- Parameters:
sessionToken- The session token to authorize with.- Returns:
- The user if the authorization was successful.
- Throws:
ParseException- Throws an exception if the authorization was unsuccessful.
-
becomeInBackground
public static void becomeInBackground(java.lang.String sessionToken, LogInCallback callback)Authorize a user with a session token. On success, this saves the session to disk, so you can retrieve the currently logged in user usinggetCurrentUser().This is preferable to using
become(java.lang.String), unless your code is already running from a background thread.- Parameters:
sessionToken- The session token to authorize with.callback- callback.done(user, e) is called when the authorization completes.
-
getCurrentUser
public static ParseUser getCurrentUser()
This retrieves the currently logged in ParseUser with a valid session, either from memory or disk if necessary.- Returns:
- The currently logged in ParseUser
-
getCurrentSessionToken
public static java.lang.String getCurrentSessionToken()
-
getCurrentSessionTokenAsync
public static <any> getCurrentSessionTokenAsync()
-
logOutInBackground
public static <any> logOutInBackground()
Logs out the currently logged in user session. This will remove the session from disk, log out of linked services, and future calls togetCurrentUser()will returnnull.This is preferable to using
logOut(), unless your code is already running from a background thread.- Returns:
- A Task that is resolved when logging out completes.
-
logOutInBackground
public static void logOutInBackground(LogOutCallback callback)
Logs out the currently logged in user session. This will remove the session from disk, log out of linked services, and future calls togetCurrentUser()will returnnull.This is preferable to using
logOut(), unless your code is already running from a background thread.
-
logOut
public static void logOut()
Logs out the currently logged in user session. This will remove the session from disk, log out of linked services, and future calls togetCurrentUser()will returnnull.Typically, you should use
logOutInBackground()instead of this, unless you are managing your own threading.Note:: Any errors in the log out flow will be swallowed due to backward-compatibility reasons. Please use
logOutInBackground()if you'd wish to handle them.
-
requestPasswordResetInBackground
public static <any> requestPasswordResetInBackground(java.lang.String email)
Requests a password reset email to be sent in a background thread to the specified email address associated with the user account. This email allows the user to securely reset their password on the Parse site.This is preferable to using
requestPasswordReset(String), unless your code is already running from a background thread.- Parameters:
email- The email address associated with the user that forgot their password.- Returns:
- A Task that is resolved when the command completes.
-
requestPasswordReset
public static void requestPasswordReset(java.lang.String email) throws ParseExceptionRequests a password reset email to be sent to the specified email address associated with the user account. This email allows the user to securely reset their password on the Parse site.Typically, you should use
requestPasswordResetInBackground(java.lang.String)instead of this, unless you are managing your own threading.- Parameters:
email- The email address associated with the user that forgot their password.- Throws:
ParseException- Throws an exception if the server is inaccessible, or if an account with that email doesn't exist.
-
requestPasswordResetInBackground
public static void requestPasswordResetInBackground(java.lang.String email, RequestPasswordResetCallback callback)Requests a password reset email to be sent in a background thread to the specified email address associated with the user account. This email allows the user to securely reset their password on the Parse site.This is preferable to using
requestPasswordReset(String), unless your code is already running from a background thread.- Parameters:
email- The email address associated with the user that forgot their password.callback- callback.done(e) is called when the request completes.
-
registerAuthenticationCallback
public static void registerAuthenticationCallback(java.lang.String authType, AuthenticationCallback callback)Registers a third party authentication callback.Note: This shouldn't be called directly unless developing a third party authentication library.
- Parameters:
authType- The name of the third party authentication source.callback- The third party authentication callback to be registered.- See Also:
AuthenticationCallback
-
logInWithInBackground
public static <any> logInWithInBackground(java.lang.String authType, java.util.Map<java.lang.String,java.lang.String> authData)Logs in a user with third party authentication credentials.Note: This shouldn't be called directly unless developing a third party authentication library.
- Parameters:
authType- The name of the third party authentication source.authData- The user credentials of the third party authentication source.- Returns:
- A
Taskis resolved when logging in completes. - See Also:
AuthenticationCallback
-
enableAutomaticUser
public static void enableAutomaticUser()
Enables automatic creation of anonymous users. After calling this method,getCurrentUser()will always have a value. The user will only be created on the server once the user has been saved, or once an object with a relation to that user or an ACL that refers to the user has been saved.Note:
ParseObject.saveEventually()will not work if an item being saved has a relation to an automatic user that has never been saved.
-
enableRevocableSessionInBackground
public static <any> enableRevocableSessionInBackground()
Enables revocable sessions. This method is only required if you wish to useParseSessionAPIs and do not have revocable sessions enabled in your application settings on your parse server.Upon successful completion of this
Task,ParseSessionAPIs will be available for use.- Returns:
- A
Taskthat will resolve when enabling revocable session
-
isAuthenticated
public boolean isAuthenticated()
Whether the ParseUser has been authenticated on this device. This will be true if the ParseUser was obtained via a logIn or signUp method. Only an authenticated ParseUser can be saved (with altered attributes) and deleted.
-
remove
public void remove(java.lang.String key)
Description copied from class:ParseObjectRemoves a key from this object's data if it exists.- Overrides:
removein classParseObject- Parameters:
key- The key to remove.
-
getSessionToken
public java.lang.String getSessionToken()
- Returns:
- the session token for a user, if they are logged in.
-
getUsername
public java.lang.String getUsername()
Retrieves the username.
-
setUsername
public void setUsername(java.lang.String username)
Sets the username. Usernames cannot be null or blank.- Parameters:
username- The username to set.
-
setPassword
public void setPassword(java.lang.String password)
Sets the password.- Parameters:
password- The password to set.
-
getEmail
public java.lang.String getEmail()
Retrieves the email address.
-
setEmail
public void setEmail(java.lang.String email)
Sets the email address.- Parameters:
email- The email address to set.
-
isNew
public boolean isNew()
Indicates whether thisParseUserwas created during this session through a call tosignUp()or by logging in with a linked service such as Facebook.
-
put
public void put(java.lang.String key, java.lang.Object value)Description copied from class:ParseObjectAdd a key-value pair to this object. It is recommended to name keys incamelCaseLikeThis.- Overrides:
putin classParseObject- Parameters:
key- Keys must be alphanumerical plus underscore, and start with a letter.value- Values may be numerical,String,JSONObject,JSONArray,JSONObject#NULL, or otherParseObjects. value may not benull.
-
fetch
public ParseUser fetch() throws ParseException
Description copied from class:ParseObjectFetches this object with the data from the server. Call this whenever you want the state of the object to reflect exactly what is on the server.- Overrides:
fetchin classParseObject- Returns:
- The
ParseObjectthat was fetched. - Throws:
ParseException- Throws an exception if the server is inaccessible.
-
signUpInBackground
public <any> signUpInBackground()
Signs up a new user. You should call this instead ofParseObject.save()for new ParseUsers. This will create a new ParseUser on the server, and also persist the session on disk so that you can access the user usinggetCurrentUser().A username and password must be set before calling signUp.
This is preferable to using
signUp(), unless your code is already running from a background thread.- Returns:
- A Task that is resolved when sign up completes.
-
signUp
public void signUp() throws ParseExceptionSigns up a new user. You should call this instead ofParseObject.save()for new ParseUsers. This will create a new ParseUser on the server, and also persist the session on disk so that you can access the user usinggetCurrentUser().A username and password must be set before calling signUp.
Typically, you should use
signUpInBackground()instead of this, unless you are managing your own threading.- Throws:
ParseException- Throws an exception if the server is inaccessible, or if the username has already been taken.
-
signUpInBackground
public void signUpInBackground(SignUpCallback callback)
Signs up a new user. You should call this instead ofParseObject.save()for new ParseUsers. This will create a new ParseUser on the server, and also persist the session on disk so that you can access the user usinggetCurrentUser().A username and password must be set before calling signUp.
This is preferable to using
signUp(), unless your code is already running from a background thread.- Parameters:
callback- callback.done(user, e) is called when the signUp completes.
-
fetchIfNeeded
public ParseUser fetchIfNeeded() throws ParseException
Description copied from class:ParseObjectIf thisParseObjecthas not been fetched (i.e.ParseObject.isDataAvailable()returnsfalse), fetches this object with the data from the server.- Overrides:
fetchIfNeededin classParseObject- Returns:
- The fetched
ParseObject. - Throws:
ParseException- Throws an exception if the server is inaccessible.
-
isLinked
public boolean isLinked(java.lang.String authType)
Indicates whether this user is linked with a third party authentication source.Note: This shouldn't be called directly unless developing a third party authentication library.
- Parameters:
authType- The name of the third party authentication source.- Returns:
trueif linked, otherwisefalse.- See Also:
AuthenticationCallback
-
linkWithInBackground
public <any> linkWithInBackground(java.lang.String authType, java.util.Map<java.lang.String,java.lang.String> authData)Links this user to a third party authentication source.Note: This shouldn't be called directly unless developing a third party authentication library.
- Parameters:
authType- The name of the third party authentication source.authData- The user credentials of the third party authentication source.- Returns:
- A
Taskis resolved when linking completes. - See Also:
AuthenticationCallback
-
unlinkFromInBackground
public <any> unlinkFromInBackground(java.lang.String authType)
Unlinks this user from a third party authentication source.Note: This shouldn't be called directly unless developing a third party authentication library.
- Parameters:
authType- The name of the third party authentication source.- Returns:
- A
Taskis resolved when unlinking completes. - See Also:
AuthenticationCallback
-
-