Users
Learn how to manage your users with QuickBlox.
Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out our Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
Create user
It’s recommended to manage user creation at your backend for production. To learn more you can refer to QuickBlox API documentation.
For POCs/MVPs or during development you may want to create users on the fly, you can use signUp()
method.
Create a user using the code snippet below. Only login (or email) and password are required. Other fields are optional.
Security & Privacy
It’s recommended to disable permission to create users with application session on production apps once user creation is implemented on your backend.
Email, full name, facebookId and phone number are PII, configure session permissions according to your privacy requirements.
Retrieve users
Get a list of users using the getUsers()
method. The code snippet below shows how to get a list of users created between the two given dates, and sorted in descending order.
Argument | Required | Description |
---|---|---|
requestBuilder | yes | Allows to set parameters for the request. |
If you want to retrieve only users updated after some specific date time and order search results, you can use operators. This is useful if you cache users somehow and do not want to obtain the whole list of users on every app start. Thus, you can use search and sort operators to list users on the page so that it is easier to see specific users.
If you want to get a paginated list of users from the server, you can set the following fields in the QBPagedRequestBuilder
class:
Field | Required | Description |
---|---|---|
perPage | no | Number of records to return in one page. |
page | no | Number of pages with results to be returned. |
Search operators
You can use search operators to get more specific search results. The code snippet below shows how to get a list of users filtered by the created_at
field and created between the two given dates.
Here are the search operators you can use to search for the exact data that you need.
Search operators | Applicable to types | Applicable to fields | Description |
---|---|---|---|
lt | number, string, date | id, created_at, updated_at, last_request_at, external_user_id, facebook_id | Less Than operator. |
gt | number, string, date | id, created_at, updated_at, last_request_at, external_user_id, facebook_id | Greater Than operator. |
gte | number, string, date | id, created_at, updated_at, last_request_at, external_user_id, facebook_id | Greater Than or Equal to operator. |
le | number, string, date | id, created_at, updated_at, last_request_at, external_user_id, facebook_id | Less or Equal to operator |
eq | number, string, date | id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id | Equal to operator. |
ne | number, string, date | id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id | Not Equal to operator. |
between | number, string, date | id, created_at, updated_at, last_request_at, external_user_id, facebook_id | Contained between values operator. |
in | number, string, date | id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id | IN array operator. |
Sort operators
You can use sort operators to order the search results. The request below will return users by the created_at
field sorted in descending order.
Here are the sort operators you can use to order the search results.
Sort operator | Applicable to types | Applicable to fields | Description |
---|---|---|---|
sortAsc | All types | id, full_name, email, login, phone, website, created_at, updated_at,last_request_at, external_user_id | Search results will be sorted in ascending order by the specified field. |
sortDesc | All types | id, full_name, email, login, phone, website, created_at, updated_at,last_request_at, external_user_id | Search results will be sorted in descending order by the specified field. |
Retrieve users by ID
To get a list of users by ID for a current account, use the following code snippet.
Or, you can retrieve a single user if needed.
Retrieve user by login
To get a list of users by login for a current account, use the following code snippet.
Retrieve user by email
To get a list of users by email for a current account, use the following code snippet.
Retrieve users by full name
To get a list of users found by the server according to the search query, use the following code snippet. Search requires min 3 characters.
Retrieve users by phone number
To get a list of users by phone number for a current account, use the following code snippet.
Retrieve user by external user ID
If you have your own database with users (we call these databases as “external databases”), you can use External User ID (ExternalID
field) in QBUser
model to link users from QuickBlox with users from your external database.
Retrieve users by Facebook ID
To get a list of users by Facebook ID for a current account, use the following code snippet.
Or, if you want to retrieve several users by Facebook IDs, use the following code lines.
Retrieve users by tags
To get a list of users by tags for a current account, use the following code snippet.
Delete user
A user can delete himself from the platform.
Reset user password
It’s possible to reset a password via email.
Make sure to enable the email confirmation. This functionality allows application users to confirm their emails. If a user doesn’t confirm the email, the emails won’t be sent to this user. As a result, a password reset functionality won’t work. To enable the email confirmation, proceed as follows:
- Go to the Dashboard => YOUR_APP => Users => Settings => User registration confirmation and check the box.
- Click the Save button.
A password reset functionality is available for the Enterprise plan. Contact the sales team for more details.
Update user
Update a user profile by calling the updateUser()
method. If you want to change your password, you need to provide 2 parameters: password
and newPassword
. The updated user
entity will be returned.
You must set null
into the user’s password
field if you do not want to change your password. Otherwise, you will need to add the user’s old password to the oldPassword
field.
You can update any other field of the user
using the updateUser()
method. Thus, the snippet below shows how to update a tagList
and customData
fields.
Field | Required | Description |
---|---|---|
tags | no | User tags. An array of Strings. A tag must include alphanumeric characters only and start with a letter. The tag must be at least 3 and no more than 15 characters long. There are no spaces in the tag format. For example, the “tagOne” format is correct while the “tag one” format is incorrect.If more that 10 tags are provided, an error is returned: tag list should contain maximum 10 tags. |
customData | no | User custom data. Should be a String. You can convert any data types to String, for example, JSON, XML , etc. |
Set user avatar
To set a user avatar, just create and upload a file to the QuickBlox cloud storage and connect it to the user.
To create a file to QuickBlox cloud storage, you should overwrite the file from the device file system to a java.io.File
and then write it to the avatar
. Then, upload the file to the QuickBlox cloud storage by calling the uploadFileTask()
method and passing the avatar
to it. Now that the file is uploaded, get the ID of the uploaded file. See this section to learn more about file upload functionality in details.
To connect the file to the user, set the ID of the uploaded file to the fileId
field of the user
and call the updateUser()
method. As a result, the user avatar gets updated.
Pass the following arguments to the updateUser()
method:
Argument | Required | Description |
---|---|---|
user | yes | Specifies user fields that should be set. |
Get user avatar
Now, other users can get your avatar by calling the downloadFileById()
method.
Argument | Required | Descriotion |
---|---|---|
userAvatarID | yes | File unique identifier. |
Was this page helpful?