PFUser Class Reference
Inherits from | PFObject : NSObject |
---|---|
Conforms to | PFSubclassing |
Declared in | PFUser.h |
Overview
The PFUser
class is a local representation of a user persisted to the Parse Data.
This class is a subclass of a PFObject, and retains the same functionality of a PFObject,
but also extends it with various user specific methods, like authentication, signing up, and validation uniqueness.
Many APIs responsible for linking a PFUser
with Facebook or Twitter have been deprecated in favor of dedicated
utilities for each social network. See PFFacebookUtils, PFTwitterUtils and PFAnonymousUtils for more information.
Accessing the Current User
+ currentUser
Gets the currently logged in user from disk and returns an instance of it.
+ (nullable instancetype)currentUser
Return Value
Returns a PFUser
that is the currently logged in user. If there is none, returns nil
.
Declared In
PFUser.h
sessionToken
The session token for the PFUser
.
@property (nullable, nonatomic, copy, readonly) NSString *sessionToken
Discussion
This is set by the server upon successful authentication.
Declared In
PFUser.h
isNew
Whether the PFUser
was just created from a request.
@property (nonatomic, assign, readonly) BOOL isNew
Discussion
This is only set after a Facebook or Twitter login.
Declared In
PFUser.h
authenticated
Whether the user is an authenticated object for the device.
@property (nonatomic, assign, readonly, getter=isAuthenticated) BOOL authenticated
Discussion
An authenticated PFUser
is one that is obtained via a signUp or
Declared In
PFUser.h
Creating a New User
+ user
Creates a new PFUser
object.
+ (instancetype)user
Return Value
Returns a new PFUser
object.
Declared In
PFUser.h
+ enableAutomaticUser
Enables automatic creation of anonymous users.
+ (void)enableAutomaticUser
Discussion
After calling this method, currentUser 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.
Warning: [PFObject saveEventually] will not work on if an item being saved has a relation to an automatic user that has never been saved.
Declared In
PFUser.h
username
The username for the PFUser
.
@property (nullable, nonatomic, strong) NSString *username
Declared In
PFUser.h
password
The password for the PFUser
.
@property (nullable, nonatomic, strong) NSString *password
Discussion
!
This will not be filled in from the server with the password. It is only meant to be set.
Declared In
PFUser.h
email
The email for the PFUser
.
@property (nullable, nonatomic, strong) NSString *email
Declared In
PFUser.h
– signUp
Signs up the user synchronously.
- (BOOL)signUp
Return Value
Returns YES
if the sign up was successful, otherwise NO
.
Discussion
This will also enforce that the username isn’t already taken.
Warning: Make sure that password and username are set before calling this method.
Declared In
PFUser.h
– signUp:
Signs up the user synchronously.
- (BOOL)signUp:(NSError **)error
Parameters
error |
Error object to set on error. |
---|
Return Value
Returns whether the sign up was successful.
Discussion
This will also enforce that the username isn’t already taken.
Warning: Make sure that password and username are set before calling this method.
Declared In
PFUser.h
– signUpInBackground
Signs up the user asynchronously.
- (BFTask PF_GENERIC ( NSNumber *) *)signUpInBackground
Return Value
The task, that encapsulates the work being done.
Discussion
This will also enforce that the username isn’t already taken.
Warning: Make sure that password and username are set before calling this method.
Declared In
PFUser.h
– signUpInBackgroundWithBlock:
Signs up the user asynchronously.
- (void)signUpInBackgroundWithBlock:(nullable PFBooleanResultBlock)block
Parameters
block |
The block to execute.
It should have the following argument signature: |
---|
Discussion
This will also enforce that the username isn’t already taken.
Warning: Make sure that password and username are set before calling this method.
Declared In
PFUser.h
– signUpInBackgroundWithTarget:selector:
Signs up the user asynchronously.
- (void)signUpInBackgroundWithTarget:(nullable id)target selector:(nullable SEL)selector
Parameters
target |
Target object for the selector. |
---|---|
selector |
The selector that will be called when the asynchrounous request is complete.
It should have the following signature: |
Discussion
This will also enforce that the username isn’t already taken.
Warning: Make sure that password and username are set before calling this method.
Declared In
PFUser.h
Logging In
+ logInWithUsername:password:
Makes a synchronous request to login a user with specified credentials.
+ (nullable instancetype)logInWithUsername:(NSString *)username password:(NSString *)password
Parameters
username |
The username of the user. |
---|---|
password |
The password of the user. |
Return Value
Returns an instance of the PFUser
on success.
If login failed for either wrong password or wrong username, returns nil
.
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ logInWithUsername:password:error:
Makes a synchronous request to login a user with specified credentials.
+ (nullable instancetype)logInWithUsername:(NSString *)username password:(NSString *)password error:(NSError **)error
Parameters
username |
The username of the user. |
---|---|
password |
The password of the user. |
error |
The error object to set on error. |
Return Value
Returns an instance of the PFUser
on success.
If login failed for either wrong password or wrong username, returns nil
.
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ logInWithUsernameInBackground:password:
Makes an asynchronous request to login a user with specified credentials.
+ (BFTask PF_GENERIC ( __kindof PFUser *) *)logInWithUsernameInBackground:(NSString *)username password:(NSString *)password
Parameters
username |
The username of the user. |
---|---|
password |
The password of the user. |
Return Value
The task, that encapsulates the work being done.
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ logInWithUsernameInBackground:password:target:selector:
Makes an asynchronous request to login a user with specified credentials.
+ (void)logInWithUsernameInBackground:(NSString *)username password:(NSString *)password target:(nullable id)target selector:(nullable SEL)selector
Parameters
username |
The username of the user. |
---|---|
password |
The password of the user. |
target |
Target object for the selector. |
selector |
The selector that will be called when the asynchrounous request is complete.
It should have the following signature: |
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ logInWithUsernameInBackground:password:block:
Makes an asynchronous request to log in a user with specified credentials.
+ (void)logInWithUsernameInBackground:(NSString *)username password:(NSString *)password block:(nullable PFUserResultBlock)block
Parameters
username |
The username of the user. |
---|---|
password |
The password of the user. |
block |
The block to execute.
It should have the following argument signature: |
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
Becoming a User
+ become:
Makes a synchronous request to become a user with the given session token.
+ (nullable instancetype)become:(NSString *)sessionToken
Parameters
sessionToken |
The session token for the user. |
---|
Return Value
Returns an instance of the PFUser
on success.
If becoming a user fails due to incorrect token, it returns nil
.
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ become:error:
Makes a synchronous request to become a user with the given session token.
+ (nullable instancetype)become:(NSString *)sessionToken error:(NSError **)error
Parameters
sessionToken |
The session token for the user. |
---|---|
error |
The error object to set on error. |
Return Value
Returns an instance of the PFUser
on success.
If becoming a user fails due to incorrect token, it returns nil
.
Discussion
Returns an instance of the successfully logged in PFUser
.
This will also cache the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ becomeInBackground:
Makes an asynchronous request to become a user with the given session token.
+ (BFTask PF_GENERIC ( __kindof PFUser *) *)becomeInBackground:(NSString *)sessionToken
Parameters
sessionToken |
The session token for the user. |
---|
Return Value
The task, that encapsulates the work being done.
Discussion
Returns an instance of the successfully logged in PFUser
.
This also caches the user locally so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ becomeInBackground:block:
Makes an asynchronous request to become a user with the given session token.
+ (void)becomeInBackground:(NSString *)sessionToken block:(nullable PFUserResultBlock)block
Parameters
sessionToken |
The session token for the user. |
---|---|
block |
The block to execute.
The block should have the following argument signature: |
Discussion
Returns an instance of the successfully logged in PFUser
. This also caches the user locally
so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
+ becomeInBackground:target:selector:
Makes an asynchronous request to become a user with the given session token.
+ (void)becomeInBackground:(NSString *)sessionToken target:(id)target selector:(SEL)selector
Parameters
sessionToken |
The session token for the user. |
---|---|
target |
Target object for the selector. |
selector |
The selector that will be called when the asynchrounous request is complete.
It should have the following signature: |
Discussion
Returns an instance of the successfully logged in PFUser
. This also caches the user locally
so that calls to currentUser will use the latest logged in user.
Declared In
PFUser.h
Revocable Session
+ enableRevocableSessionInBackground
Enables revocable sessions and migrates the currentUser session token to use revocable session if needed.
+ (BFTask *)enableRevocableSessionInBackground
Return Value
An instance of BFTask
that is completed when revocable
sessions are enabled and currentUser token is migrated.
Discussion
This method is required if you want to use PFSession APIs
and your application’s ‘Require Revocable Session’ setting is turned off on http://parse.com
app settings.
After returned BFTask
completes - PFSession class and APIs will be available for use.
Declared In
PFUser.h
+ enableRevocableSessionInBackgroundWithBlock:
Enables revocable sessions and upgrades the currentUser session token to use revocable session if needed.
+ (void)enableRevocableSessionInBackgroundWithBlock:(nullable PFUserSessionUpgradeResultBlock)block
Parameters
block |
Block that will be called when revocable sessions are enabled and currentUser token is migrated. |
---|
Discussion
This method is required if you want to use PFSession APIs
and legacy sessions are enabled in your application settings on http://parse.com/
.
After returned BFTask
completes - PFSession class and APIs will be available for use.
Declared In
PFUser.h
Logging Out
+ logOut
Synchronously logs out the currently logged in user on disk.
+ (void)logOut
Declared In
PFUser.h
+ logOutInBackground
Asynchronously logs out the currently logged in user.
+ (BFTask *)logOutInBackground
Return Value
An instance of BFTask
, that is resolved with nil
result when logging out completes.
Discussion
This will also remove the session from disk, log out of linked services
and all future calls to currentUser will return nil
. This is preferrable to using logOut,
unless your code is already running from a background thread.
Declared In
PFUser.h
+ logOutInBackgroundWithBlock:
Asynchronously logs out the currently logged in user.
+ (void)logOutInBackgroundWithBlock:(nullable PFUserLogoutResultBlock)block
Parameters
block |
A block that will be called when logging out completes or fails. |
---|
Discussion
This will also remove the session from disk, log out of linked services
and all future calls to currentUser will return nil
. This is preferrable to using logOut,
unless your code is already running from a background thread.
Declared In
PFUser.h
Requesting a Password Reset
+ requestPasswordResetForEmail:
Synchronously Send a password reset request for a specified email.
+ (BOOL)requestPasswordResetForEmail:(NSString *)email
Parameters
email |
Email of the account to send a reset password request. |
---|
Return Value
Returns YES
if the reset email request is successful. NO
- if no account was found for the email address.
Discussion
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declared In
PFUser.h
+ requestPasswordResetForEmail:error:
Synchronously send a password reset request for a specified email and sets an error object.
+ (BOOL)requestPasswordResetForEmail:(NSString *)email error:(NSError **)error
Parameters
email |
Email of the account to send a reset password request. |
---|---|
error |
Error object to set on error. |
Return Value
Returns YES
if the reset email request is successful. NO
- if no account was found for the email address.
Discussion
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declared In
PFUser.h
+ requestPasswordResetForEmailInBackground:
Send a password reset request asynchronously for a specified email and sets an error object. If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
+ (BFTask PF_GENERIC ( NSNumber *) *)requestPasswordResetForEmailInBackground:(NSString *)email
Parameters
email |
Email of the account to send a reset password request. |
---|
Return Value
The task, that encapsulates the work being done.
Declared In
PFUser.h
+ requestPasswordResetForEmailInBackground:block:
Send a password reset request asynchronously for a specified email.
+ (void)requestPasswordResetForEmailInBackground:(NSString *)email block:(nullable PFBooleanResultBlock)block
Parameters
email |
Email of the account to send a reset password request. |
---|---|
block |
The block to execute.
It should have the following argument signature: |
Discussion
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declared In
PFUser.h
+ requestPasswordResetForEmailInBackground:target:selector:
Send a password reset request asynchronously for a specified email and sets an error object.
+ (void)requestPasswordResetForEmailInBackground:(NSString *)email target:(id)target selector:(SEL)selector
Parameters
email |
Email of the account to send a reset password request. |
---|---|
target |
Target object for the selector. |
selector |
The selector that will be called when the asynchronous request is complete.
It should have the following signature: |
Discussion
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declared In
PFUser.h
Third-party Authentication
+ registerAuthenticationDelegate:forAuthType:
Registers a third party authentication delegate.
+ (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegate forAuthType:(NSString *)authType
Parameters
delegate |
The third party authenticaiton delegate to be registered. |
---|---|
authType |
The name of the type of third party authentication source. |
Discussion
Note: This method shouldn’t be invoked directly unless developing a third party authentication library.
See Also
Declared In
PFUser.h
+ logInWithAuthTypeInBackground:authData:
Logs in a user with third party authentication credentials.
+ (BFTask PF_GENERIC ( PFUser *) *)logInWithAuthTypeInBackground:(NSString *)authType authData:(NSDictionary PF_GENERIC ( NSString *, NSString *) *)authData
Parameters
authType |
The name of the type of third party authentication source. |
---|---|
authData |
The user credentials of the third party authentication source. |
Return Value
A BFTask
that is resolved to PFUser
when logging in completes.
Discussion
Note: This method shouldn’t be invoked directly unless developing a third party authentication library.
See Also
Declared In
PFUser.h
– linkWithAuthTypeInBackground:authData:
Links this user to a third party authentication library.
- (BFTask PF_GENERIC ( NSNumber *) *)linkWithAuthTypeInBackground:(NSString *)authType authData:(NSDictionary PF_GENERIC ( NSString *, NSString *) *)authData
Parameters
authType |
The name of the type of third party authentication source. |
---|---|
authData |
The user credentials of the third party authentication source. |
Return Value
A BFTask
that is resolved to @YES
if linking succeeds.
Discussion
Note: This method shouldn’t be invoked directly unless developing a third party authentication library.
See Also
Declared In
PFUser.h
– unlinkWithAuthTypeInBackground:
Unlinks this user from a third party authentication library.
- (BFTask PF_GENERIC ( NSNumber *) *)unlinkWithAuthTypeInBackground:(NSString *)authType
Parameters
authType |
The name of the type of third party authentication source. |
---|
Return Value
A BFTask
that is resolved to @YES
if unlinking succeeds.
Discussion
Note: This method shouldn’t be invoked directly unless developing a third party authentication library.
See Also
Declared In
PFUser.h
– isLinkedWithAuthType:
Indicates whether this user is linked with a third party authentication library of a specific type.
- (BOOL)isLinkedWithAuthType:(NSString *)authType
Parameters
authType |
The name of the type of third party authentication source. |
---|
Return Value
YES
if the user is linked with a provider, otherwise NO
.
Discussion
Note: This method shouldn’t be invoked directly unless developing a third party authentication library.
See Also
Declared In
PFUser.h