User representation for LeanCloud User
LeanCloud provides a default user model to facilitate user
management at application level. Users can be managed by email,
mobile phone number, or simply a username.
Upon sign-up a session token is issued to user, which shall be used
to authenticate the user in subsequent requests. The session token
of logged-in user is available at
User::getCurrentSessionToken()
and current user at
User::getCurrentUser()
Providing a token, the user can be conveniently authenticated and
fetched by
User::become($token)
Methods summary
public
LeanCloud\User
|
#
setUsername( string $username )
Set username
Parameters
Returns
|
public
LeanCloud\User
|
#
setEmail( string $email )
Set email
Parameters
Returns
|
public
LeanCloud\User
|
#
setPassword( string $password )
Set password
Parameters
Returns
|
public
LeanCloud\User
|
|
public
|
#
signUp( )
Sign-up user
It will also auto-login and set current user.
Throws
|
public
|
|
public
|
#
updatePassword( string $old, string $new )
Update password with old password
Update password with old password
Parameters
- $old
- Old password
- $new
- New password
Throws
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
#
getSessionToken( )
Get session token of user
Get session token of user
Returns
string
|
public static
|
#
setCurrentSessionToken( string $token )
Set session token as of logged-in user
Set session token as of logged-in user
Save session token after a user logs in. It will clear session token
if given token is null.
Parameters
- $token
- Session token of logged-in user
|
public static
string
|
|
public static
LeanCloud\User
|
#
getCurrentUser( )
Get currently logged-in user
Get currently logged-in user
Returns
|
public static
|
|
public static
|
#
clearCurrentUser( )
Clear logged-in user and session token.
Clear logged-in user and session token.
|
public
|
|
public
boolean
|
#
isAuthenticated( )
Test if user logged in and session token is valid.
Test if user logged in and session token is valid.
Returns
boolean
|
public
array
|
#
getRoles( )
Get roles the user belongs to
Get roles the user belongs to
Returns
array Array of Role
|
public static
LeanCloud\User
|
#
become( string $token )
Log-in user by session token
Log-in user by session token
And set current user.
Parameters
Returns
Throws
|
public static
LeanCloud\User
|
#
logIn( string $username, string $password )
Log-in user by username and password
Log-in user by username and password
And set current user.
Parameters
Returns
Throws
|
public static
LeanCloud\User
|
#
logInWithEmail( string $email, string $password )
Log-in user by email and password
Log-in user by email and password
And set current user.
Parameters
Returns
Throws
|
public static
|
|
public static
LeanCloud\User
|
#
logInWithMobilePhoneNumber( string $phoneNumber, string $password )
Log-in user by mobile phone and password
Log-in user by mobile phone and password
Parameters
Returns
|
public static
LeanCloud\User
|
#
logInWithSmsCode( string $phoneNumber, string $smsCode )
Log-in user by mobile phone and SMS code.
Log-in user by mobile phone and SMS code.
Log-in user with SMS code, which can be requested by
requestLoginSmsCode . It will set current user.
Parameters
- $phoneNumber
- Registered mobile phone number
- $smsCode
Returns
|
public static
|
#
requestLoginSmsCode( string $phoneNumber )
Request login SMS code
Send user mobile phone a message with SMS code, which can be used
for login then.
Parameters
- $phoneNumber
- Register mobile phone number
|
public static
|
#
requestEmailVerify( string $email )
Request email verify
Send user an email to verify email.
Parameters
|
public static
|
#
requestPasswordReset( string $email )
Request password reset by email
Request password reset by email
Parameters
|
public static
|
#
requestPasswordResetBySmsCode( string $phoneNumber )
Request password reset by SMS
Request password reset by SMS
Send user mobile phone a message with SMS code.
Parameters
- $phoneNumber
- Registered mobile phone number
|
public static
|
#
resetPasswordBySmsCode( string $smsCode, string $newPassword )
Reset password by SMS code.
Reset password by SMS code.
Parameters
|
public static
|
#
requestMobilePhoneVerify( string $phoneNumber )
Request mobile phone verify.
Request mobile phone verify.
Send user mobile phone a message with SMS code.
Parameters
|
public static
|
#
verifyMobilePhone( string $smsCode )
Verify mobile phone by SMS code
Verify mobile phone by SMS code
Parameters
|
public static
|
#
requestChangePhoneNumber( string $phoneNumber )
Request mobile phone verify before updating it.
Request mobile phone verify before updating it.
Parameters
|
public static
|
#
changePhoneNumber( string $smsCode, string $phoneNumber )
Update mobile phone number by SMS code.
Update mobile phone number by SMS code.
Parameters
|
public static
LeanCloud\User
|
#
signUpOrLoginByMobilePhone( string $phoneNumber, string $smsCode )
Sign up user by mobile phone and SMS code
Sign up user by mobile phone and SMS code
Parameters
Returns
|
public static
LeanCloud\User
|
#
logInWith( string $provider, array $authToken )
Log-in with 3rd party auth data
Log-in with 3rd party auth data
Log-in with 3rd party provider auth data. If the auth data has been
linked previously with user, it will login as that user. Else a
new user will be created with generated username. It will set
current user.
Parameters
- $provider
- Provider name
- $authToken
- Auth token
Returns
|
public
LeanCloud\User
|
#
linkWith( string $provider, array $authToken )
Link user with 3rd party provider
Link user with 3rd party provider
Parameters
- $provider
- Provider name e.g. "weibo", "weixin"
- $authToken
- Array of id, token, and expiration info
Returns
|
public
LeanCloud\User
|
#
unlinkWith( string $provider )
Unlink user with a provider
Unlink user with a provider
Parameters
Returns
|