Constructor
new User(attributes)
Parameters:
Name | Type | Description |
---|---|---|
attributes |
Object
|
The initial set of data to store in the user. |
Extends
Members
createdAt :Date
The first time this object was saved on the server.
Properties:
Name | Type | Description |
---|---|---|
createdAt |
- Inherited From:
Type:
-
Date
updatedAt :Date
The last time this object was updated on the server.
Properties:
Name | Type | Description |
---|---|---|
updatedAt |
- Inherited From:
Type:
-
Date
Methods
(static) allowCustomUserClass(isAllowed)
Allow someone to define a custom User class without className being rewritten to _User. The default behavior is to rewrite User to _User for legacy reasons. This allows developers to override that behavior.
Parameters:
Name | Type | Description |
---|---|---|
isAllowed |
Boolean
|
Whether or not to allow custom User class |
(static) become(sessionToken, options) → {Promise}
Logs in a user with a session token. On success, this saves the session
to disk, so you can retrieve the currently logged in user using
current
.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
sessionToken |
String
|
The sessionToken to log in with. |
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login completes.
(static) current() → {Parse.Object}
Retrieves the currently logged in ParseUser with a valid session, either from memory or localStorage, if necessary.
(static) currentAsync() → {Promise}
Retrieves the currently logged in ParseUser from asynchronous Storage.
Returns:
- Type:
-
Promise
A Promise that is resolved with the currently logged in Parse User
(static) disableUnsafeCurrentUser()
Disables the use of become or the current user in any environment. These features are disabled on servers by default, since they depend on global objects that are not memory-safe for most servers.
(static) enableRevocableSession(options) → {Promise}
Allows a legacy application to start using revocable sessions. If the current session token is not revocable, a request will be made for a new, revocable session. It is not necessary to call this method from cloud code unless you are handling user signup or login from the server side. In a cloud code call, this function will not attempt to upgrade the current token.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is resolved when the process has completed. If a replacement session token is requested, the promise will be resolved after a new token has been fetched.
(static) enableUnsafeCurrentUser()
Enables the use of become or the current user in a server environment. These features are disabled by default, since they depend on global objects that are not memory-safe for most servers.
(static) extend(protoProps, classProps) → {Class}
Adds functionality to the existing Parse.User class
Parameters:
Name | Type | Description |
---|---|---|
protoProps |
Object
|
A set of properties to add to the prototype |
classProps |
Object
|
A set of static properties to add to the class |
Returns:
- Type:
-
Class
The newly extended Parse.User class
(static) logIn(username, password, options) → {Promise}
Logs in a user with a username (or email) and password. On success, this
saves the session to disk, so you can retrieve the currently logged in
user using current
.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
username |
String
|
The username (or email) to log in with. |
password |
String
|
The password to log in with. |
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login completes.
(static) logOut() → {Promise}
Logs out the currently logged in user session. This will remove the
session from disk, log out of linked services, and future calls to
current
will return null
.
Returns:
- Type:
-
Promise
A promise that is resolved when the session is destroyed on the server.
(static) requestPasswordReset(email, options) → {Promise}
Requests 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.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
email |
String
|
The email address associated with the user that forgot their password. |
options |
Object
|
Returns:
- Type:
-
Promise
(static) signUp(username, password, attrs, options) → {Promise}
Signs up a new user with a username (or email) and password. This will create a new Parse.User on the server, and also persist the session in localStorage so that you can access the user using #current.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
username |
String
|
The username (or email) to sign up with. |
password |
String
|
The password to sign up with. |
attrs |
Object
|
Extra fields to set on the new user. |
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the signup completes.
_cleanupAuthData()
Removes null values from authData (which exist temporarily for unlinking)
_getId()
Returns a local or server Id used uniquely identify this object
- Inherited From:
_getStateIdentifier()
Returns a unique identifier used to pull data from the State Controller.
- Inherited From:
_isLinked()
Checks whether a user is linked to a service.
_linkWith()
Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can call linkWith on the user (even if it doesn't exist yet on the server).
_logOutWith()
Deauthenticates a single provider (e.g. removing access tokens from the Facebook SDK).
_logOutWithAll()
Deauthenticates all providers.
_preserveFieldsOnFetch()
Class instance method used to maintain specific keys when a fetch occurs. Used to ensure that the session token is not lost.
_synchronizeAllAuthData()
Synchronizes authData for all providers.
_synchronizeAuthData()
Synchronizes auth data for a provider (e.g. puts the access token in the right place to be used by the Facebook SDK).
_unlinkFrom()
Unlinks a user from a service.
_upgradeToRevocableSession(options) → {Promise}
Request a revocable session token to replace the older style of token.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is resolved when the replacement token has been fetched.
add(attr, item) → {ParseObject|Boolean}
Atomically add an object to the end of the array associated with a given key.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The item to add. |
Returns:
- Type:
-
ParseObject
|Boolean
addAll(attr, items)
Atomically add the objects to the end of the array associated with a given key.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The items to add. |
addAllUnique(attr, items)
Atomically add the objects to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The objects to add. |
addUnique(attr, item)
Atomically add an object to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to add. |
authenticated()
Checks whether this user is the current user and has been authenticated.
Returns:
(Boolean) whether this user is the current user and is logged in.
clear() → {ParseObject|boolean}
Clears all attributes on a model
- Inherited From:
Returns:
- Type:
-
ParseObject
|boolean
clone() → {Parse.Object}
Creates a new model with identical attributes to this one.
- Inherited From:
Returns:
- Type:
-
Parse.Object
destroy()
Wrap the default destroy behavior with functionality that logs out the current user when it is destroyed
- Overrides:
dirty(attr) → {Boolean}
Returns true if this object has been modified since its last save/refresh. If an attribute is specified, it returns true only if that particular attribute has been modified since the last save/refresh.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
An attribute name (optional). |
Returns:
- Type:
-
Boolean
dirtyKeys() → {Array.<String>}
Returns an array of keys that have been modified since last save/refresh
- Inherited From:
Returns:
- Type:
-
Array.<String>
equals(other) → {Boolean}
Determines whether this ParseObject is equal to another ParseObject
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
other |
Object
|
An other object ot compare |
Returns:
- Type:
-
Boolean
escape(attr)
Gets the HTML-escaped value of an attribute.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The string name of an attribute. |
existed() → {Boolean}
Returns true if this object was created by the Parse server when the object might have already been there (e.g. in the case of a Facebook login)
- Inherited From:
Returns:
- Type:
-
Boolean
fetch()
Wrap the default fetch behavior with functionality to save to local storage if this is current user.
- Overrides:
fetchWithInclude()
Wrap the default fetchWithInclude behavior with functionality to save to local storage if this is current user.
- Overrides:
get(attr)
Gets the value of an attribute.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The string name of an attribute. |
getEmail() → {String}
Returns get("email").
Returns:
- Type:
-
String
getSessionToken() → {String}
Returns the session token for this user, if the user has been logged in, or if it is the result of a query with the master key. Otherwise, returns undefined.
Returns:
- Type:
-
String
the session token, or undefined
getUsername() → {String}
Returns get("username").
Returns:
- Type:
-
String
has(attr) → {Boolean}
Returns true
if the attribute contains a value that is not
null or undefined.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The string name of the attribute. |
Returns:
- Type:
-
Boolean
increment(attr, amount)
Atomically increments the value of the given attribute the next time the object is saved. If no amount is specified, 1 is used by default.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
amount |
Number
|
The amount to increment by (optional). |
isCurrent() → {Boolean}
Returns true if current
would return this user.
Returns:
- Type:
-
Boolean
isNew() → {Boolean}
Returns true if this object has never been saved to Parse.
- Inherited From:
Returns:
- Type:
-
Boolean
isValid() → {Boolean}
Checks if the model is currently in a valid state.
- Inherited From:
Returns:
- Type:
-
Boolean
logIn(options) → {Promise}
Logs in a Parse.User. On success, this saves the session to disk,
so you can retrieve the currently logged in user using
current
.
A username and password must be set before calling logIn.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled with the user when the login is complete.
newInstance() → {Parse.Object}
Creates a new instance of this object. Not to be confused with clone()
- Inherited From:
Returns:
- Type:
-
Parse.Object
op(attr) → {Parse.Op}
Returns an instance of a subclass of Parse.Op describing what kind of modification has been performed on this field since the last time it was saved. For example, after calling object.increment("x"), calling object.op("x") would return an instance of Parse.Op.Increment.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
Returns:
- Type:
-
Parse.Op
The operation, or undefined if none.
relation(String) → {Parse.Relation}
Gets a relation on the given class for the attribute.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
String |
attr The attribute to get the relation for. |
Returns:
- Type:
-
Parse.Relation
remove(attr, item)
Atomically remove all instances of an object from the array associated with a given key.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to remove. |
removeAll(attr, items)
Atomically remove all instances of the objects from the array associated with a given key.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The object to remove. |
revert()
Clears any changes to this object made since the last call to save()
- Inherited From:
save()
Wrap the default save behavior with functionality to save to local storage if this is current user.
- Overrides:
set(key, value, options) → {Boolean}
Sets a hash of model attributes on the object.
You can call it with an object containing keys and values, or with one key and value. For example:
gameTurn.set({ player: player1, diceRoll: 2 }, { error: function(gameTurnAgain, error) { // The set failed validation. } }); game.set("currentPlayer", player2, { error: function(gameTurnAgain, error) { // The set failed validation. } }); game.set("finished", true);
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
key |
String
|
The key to set. |
value |
The value to give it. |
|
options |
Object
|
A set of options for the set.
The only supported option is |
Returns:
- Type:
-
Boolean
true if the set succeeded.
setACL(acl, options) → {Boolean}
Sets the ACL to be used for this object.
- Inherited From:
- See:
Parameters:
Name | Type | Description |
---|---|---|
acl |
Parse.ACL
|
An instance of Parse.ACL. |
options |
Object
|
Returns:
- Type:
-
Boolean
Whether the set passed validation.
setEmail(email) → {Boolean}
Calls set("email", email) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
email |
String
|
Returns:
- Type:
-
Boolean
setPassword(password, options) → {Boolean}
Calls set("password", password, options) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
password |
String
|
|
options |
Object
|
Returns:
- Type:
-
Boolean
setUsername(username, options) → {Boolean}
Calls set("username", username, options) and returns the result.
Parameters:
Name | Type | Description |
---|---|---|
username |
String
|
|
options |
Object
|
Returns:
- Type:
-
Boolean
signUp(attrs, options) → {Promise}
Signs up a new user. You should call this instead of save for
new Parse.Users. This will create a new Parse.User on the server, and
also persist the session on disk so that you can access the user using
current
.
A username and password must be set before calling signUp.
Calls options.success or options.error on completion.
Parameters:
Name | Type | Description |
---|---|---|
attrs |
Object
|
Extra fields to set on the new user, or null. |
options |
Object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the signup finishes.
toJSON() → {Object}
Returns a JSON version of the object suitable for saving to Parse.
- Inherited From:
Returns:
- Type:
-
Object
toPointer() → {Pointer}
Gets a Pointer referencing this Object.
- Inherited From:
Returns:
- Type:
-
Pointer
unset(attr)
Remove an attribute from the model. This is a noop if the attribute doesn't exist.
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The string name of an attribute. |
validate(attrs)
You should not call this function directly unless you subclass
Parse.Object
, in which case you can override this method
to provide additional validation on set
and
save
. Your implementation should return
- Inherited From:
- See:
Parameters:
Name | Type | Description |
---|---|---|
attrs |
Object
|
The current data to validate. |
Returns:
False if the data is valid. An error object otherwise.