MLUser Class Reference

Inherits from MLObject : NSObject
Conforms to MLSubclassing
Declared in MLUser.h

Overview

A MLUser object represent a user persisted to the MaxLeap.

Other Methods

+ leapClassName

The name of the MLUserclass in the REST API. This is a required MLSubclassing method

+ (NSString *)leapClassName

Declared In

MLUser.h

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 MLUserthat is the currently logged in user. If there is none, returns nil.

Declared In

MLUser.h

Creating a New User

+ user

Creates a new MLUserobject.

+ (instancetype)user

Return Value

Returns a new MLUserobject.

Declared In

MLUser.h

Properties

  username

The username for the MLUser.

@property (nonatomic, strong, nullable) NSString *username

Declared In

MLUser.h

  password

The password for the MLUser. This will not be filled in from the server with the password. It is only meant to be set.

@property (nonatomic, strong, nullable) NSString *password

Declared In

MLUser.h

  email

The email for the MLUser.

@property (nonatomic, strong, nullable) NSString *email

Declared In

MLUser.h

  emailVerified

Whether the email is verified.

@property (nonatomic, readonly) BOOL emailVerified

Declared In

MLUser.h

  mobilePhone

The mobile phone number for the MLUser.

@property (nonatomic, strong, nullable) NSString *mobilePhone

Declared In

MLUser.h

  mobilePhoneVerified

Whether the mobile phone number is verified. If true, the user can login using mobile phone number and smscode.

@property (nonatomic, readonly) BOOL mobilePhoneVerified

Declared In

MLUser.h

  sessionToken

The session token for the MLUser. This is set by the server upon successful authentication.

@property (nonatomic, strong, nullable) NSString *sessionToken

Declared In

MLUser.h

  isNew

Whether the MLUserwas just created from a request. This is only set after a Facebook or Twitter login.

@property (readonly, nonatomic) BOOL isNew

Declared In

MLUser.h

  oauthData

The OAuth data from 3rd party platforms.

@property (readonly, nonatomic) NSDictionary *oauthData

Declared In

MLUser.h

Authenticated status

– isAuthenticated

Whether the user is an authenticated object for the device. An authenticated MLUser is one that is obtained via a signUp or logIn method. An authenticated object is required in order to save (with altered values) or delete it.

- (BOOL)isAuthenticated

Return Value

Returns whether the user is authenticated.

Declared In

MLUser.h

Signing up

– signUpInBackgroundWithBlock:

Signs up the user asynchronously. Make sure that password and username are set. This will also enforce that the username isn’t already taken.

- (void)signUpInBackgroundWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLUser.h

Logging in

+ logInWithUsernameInBackground:password:block:

Makes an asynchronous request to log in a user with specified credentials. Returns an instance of the successfully logged in MLUser. This will also cache the user locally so that calls to currentUser will use the latest logged in user.

+ (void)logInWithUsernameInBackground:(NSString *)username password:(NSString *)password block:(nullable MLUserResultBlock)block

Parameters

username

The username of the user.

password

The password of the user.

block

The block to execute. The block should have the following argument signature: (MLUser user, NSError error)

Declared In

MLUser.h

Becoming a user

+ becomeInBackgroundWithSessionToken:block:

Makes an asynchronous request to become a user with the given session token. Returns an instance of the successfully logged in MLUser. This also caches the user locally so that calls to currentUser will use the latest logged in user. The selector for the callback should look like: myCallback:(MLUser *)user error:(NSError **)error

+ (void)becomeInBackgroundWithSessionToken:(NSString *)sessionToken block:(nullable MLUserResultBlock)block

Parameters

sessionToken

The session token for the user.

block

The block to execute. The block should have the following argument signature: (MLUser user, NSError error)

Declared In

MLUser.h

Logging Out

+ logOut

Logs out the currently logged in user on disk.

+ (void)logOut

Declared In

MLUser.h

Requesting a Password Reset

+ requestPasswordResetForEmailInBackground:block:

Send a password reset request asynchronously for a specified email. If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.

+ (void)requestPasswordResetForEmailInBackground:(NSString *)email block:(nullable MLBooleanResultBlock)block

Parameters

email

Email of the account to send a reset password request.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLUser.h

Requesting a Email Verify

+ requestEmailVerifyForEmailInBackground:block:

Send a email verify request asynchronously for a specified email. If a user account exists with that email, an email will be sent to that address with instructions on how to verify their email.

+ (void)requestEmailVerifyForEmailInBackground:(NSString *)email block:(nullable MLBooleanResultBlock)block

Parameters

email

Email of the account to verify.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLUser.h

– checkIsPasswordMatchInBackground:block:

Check whether the password matches the user.

- (void)checkIsPasswordMatchInBackground:(NSString *)password block:(nullable MLBooleanResultBlock)block

Parameters

password

a password

block

The block to execute. The block should have the following argument signature: (BOOL isMatch, NSError *error)

Declared In

MLUser.h

+ checkUsernameExists:block:

Check the username is exist or not.

+ (void)checkUsernameExists:(NSString *)username block:(nullable MLBooleanResultBlock)block

Parameters

username

The username to check

block

The block to execute. The block should have the following argument signature: (BOOL isExist, NSError *error)

Discussion

Empty username is not exist becuause it’s not valid.

Declared In

MLUser.h

MLSmsCodeUtils Methods

+ requestLoginSmsCodeWithPhoneNumber:block:

Send a sms code login request asynchronously for a specified mobile phone number. The sms code will send to that mobile phone and then the use can use the code to login without a password.

+ (void)requestLoginSmsCodeWithPhoneNumber:(NSString *)phoneNumber block:(nullable MLBooleanResultBlock)block

Parameters

phoneNumber

Phone number to receive the code.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLSmsCodeUtils.h

+ loginWithPhoneNumber:smsCode:block:

Login with the login sms code. The code can be requested by invoking requestLoginSmsCodeWithPhoneNumber:block:.

+ (void)loginWithPhoneNumber:(NSString *)phoneNumber smsCode:(NSString *)smsCode block:(nullable MLUserResultBlock)block

Parameters

phoneNumber

Phone number as username

smsCode

The login sms code requested by invoking requestLoginSmsCodeWithPhoneNumber:block:.

block

The block to execute. The block should have the following argument signature: (MLUser user, NSError error)

Declared In

MLSmsCodeUtils.h

– requestMobilePhoneVerifySmsCodeWithBlock:

Send a sms code asynchronously for verifing the user’s mobilePhone. If the user[@"mobilePhone"] exists, a sms code will be sent to that phone which can be used to verify the user’s mobilePhone.

- (void)requestMobilePhoneVerifySmsCodeWithBlock:(nullable MLBooleanResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLSmsCodeUtils.h

– verifyMobilePhoneWithSmsCode:block:

Verify the mobilePhone field of the user. After successfully verifing, the

- (void)verifyMobilePhoneWithSmsCode:(NSString *)smsCode block:(nullable MLBooleanResultBlock)block

Parameters

smsCode

The sms code requested by invoking requestMobilePhoneVerifySmsCodeWithBlock:.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLSmsCodeUtils.h

+ requestPasswordResetSmsCodeWithPhoneNumber:block:

Send a password reset sms code asynchronously for a specified phone number. If a user account exists with that phone number, a sms code which can be used to reset password for the user account will be sent to that phone.

+ (void)requestPasswordResetSmsCodeWithPhoneNumber:(NSString *)phoneNumber block:(nullable MLBooleanResultBlock)block

Parameters

phoneNumber

The phone number to receive the code.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLSmsCodeUtils.h

+ resetPasswordWithPhoneNumber:smsCode:password:block:

Reset password for user account with the phoneNumber.

+ (void)resetPasswordWithPhoneNumber:(NSString *)phoneNumber smsCode:(NSString *)smsCode password:(NSString *)password block:(nullable MLBooleanResultBlock)block

Parameters

phoneNumber

The phone number of user account.

smsCode

Sms code requested by invoking requestPasswordResetSmsCodeWithPhoneNumber:block:

password

New password.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLSmsCodeUtils.h