In AnQi CMS, implement reading levels for specific documents (such as paid documents or exclusive member content) [en]read_levelControl is a very practical feature that helps us better manage content permissions and achieve differentiated content operations.This mechanism is not only flexible, but also closely integrated with the user system, allowing us to determine what content users can see based on their identity or payment status.

Next, we will explore how to efficiently utilize AnQi CMS [en]read_levelTo implement document access control.

Understandingread_levelcore mechanism

Safe CMS provides a namedread_levelThe parameter, it is an integer value used to identify the minimum reading level required for the document.In simple terms, the higher the number, the higher the reading permission requirements for the document.read_levelvalue.

At the same time, the user system of AnQi CMS supports user grouping, and each user group can have a correspondinglevelvalue. When a user tries to access a settingread_levelWhen the document is opened, the system will compare the document'sread_levelwith the user group of the currently logged-in user'slevel. Only when the user'slevel is greater than or equal toDocument'sread_levelUser can read the document content normally when this condition is met. If the user's level is insufficient, or if the document is set to require payment at the same time.price(price), the user also needs to meet the payment conditions.

How to set the document'sread_levelandprice

In AnQi CMS, when publishing or editing documents, you canarchivePublishset the document'sread_levelandprice.

  • read_level(int, integer value):This is the document's reading level.
    • If set to0(default), indicating that the document is open to all users without any reading level restrictions.
    • If set to1/2/3If, it means that the user's group level needs to reach or exceed this value to read.
  • price(int, unit is cent):This is the price of the document.
    • If set to0[Default], indicating that the document is free.
    • If set to100means that the price of the document is 1 yuan (100 points).

For example, if you have a document that is specifically prepared for VIP members, and your VIP grouplevelYes10, then you can set this document asread_levelset10If this VIP document requires additional payment, you can also set it at the same timeprice.

Access judgment logic on the user side

When a user tries to view a document, the front-end page needs to interact with the API of Anqi CMS to determine if the user has the right to access. This usually involves several steps and interfaces:

  1. Get document details:Firstly, we will get the details of the document byarchiveDetailthe interface, including the parameters of the document.read_levelandpriceThese are the basis for our judgment.

  2. Check if the document is paid:If fromarchiveDetailthe data returned by the interface, the document'spricevalue is greater than0This means that it is a paid document. In this case, we need to call further.archiveOrderCheckInterface, pass in the document ID to check if the currently logged-in user has paid for this document.

    • archiveOrderCheckThe interface will returntrueorfalseto indicate whether the user has paid.
  3. to obtain the user's level information:If the document hasread_levellimits (i.e.,read_levelgreater0), we need to obtain the current logged-in user's level. This is usually achieved by combining the following two interfaces:

    • InvokeuserDetailInterface to get the basic information of the currently logged-in user, which will includegroup_id(User group ID).
    • Then calluserGroupDetailinterface, passing ingroup_idGet detailed information about the user group to which the user belongs, which will include information about the user group.levelvalue.
  4. Make a comprehensive judgment on access permissions:

    • If the document is paid (price > 0):First, checkarchiveOrderCheckThe result returned. If not paid, the user has no right to read, and the page can prompt the user to purchase. If paid, continue to check.read_level.
    • If there is a level restriction on the document (read_level > 0):Compare the user's group to thelevelof the document.read_levelIf the user'slevelis less than theread_levelof the document, the user does not have permission to read, and the page can prompt the user to upgrade to a member.
    • If the document does not have price and level restrictions (price = 0andread_level = 0): then all users (including those not logged in) can read directly.

Detailed to custom field access control

The document model (Model) feature of AnQi CMS also provides a very powerful option, allowing you to set options in the document.Custom fieldsAlso set access permissions.moduleDetailYou will see a model field information returned by the interfacefollow_levelparameter. If there is a custom fieldfollow_levelsettruethen the content of this field will automatically follow the restrictionsread_levelof the document itself.

This means that you can make a specific information block in the document, such as a detailed report download link, or a contact method, available only to users who meet certain conditionsread_levelShow when a condition is met. When fetching document details on the frontend,archiveDetailthe interface will return the data of these custom fields.extrayou only need to parseextrathe data in it, and according to the fieldsfollow_levelStatus and the user level and document mentioned earlier.read_levelLogic to determine whether to display the content of this custom field.

Overview of the key steps for frontend implementation.

To provide users with a smooth experience, the front-end page can organize the code in such a logic when loading the document:

  1. ThrougharchiveDetailInterface request document ID or filename to get document details.
  2. Check in the obtained document details.priceandread_levelthe value.
  3. If the user is logged in, get theiruserId, and proceed throughuserDetailanduserGroupDetailInterface fetches the current user'slevel.
  4. Determine based on the following priority:
    • Ifdocument.price > 0And the user has not paid (call)archiveOrderCheckConfirmation), then display the purchase prompt and hide the document content.
    • Otherwise, ifdocument.read_level > 0anduser_level < document.read_levelIf so, display the membership upgrade prompt and hide the document content.
    • Otherwise, the user has reading permissions and the document content is displayed normally.
  5. For the documentextracustom fields, if theirfollow_levelattribute oftrueIf so, the same logic as above should be applied.read_levelCheck the logic to determine whether to display the field content.

With such a combination, you can flexibly control the reading level of documents in the Anqi CMS, whether it's creating paid reading content, exclusive articles for members, or managing permissions for specific parts of the document, it can be handled easily.


Common Questions (FAQ)

1.read_levelWhat is the default value? When the document'sread_levelmeans when it is 0? read_leveldefault value is0. When the document'sread_levelset0When, it means that the document is open to all users, regardless of whether they are logged in or not, and regardless of the user groups they belong to.levelNo matter how many, users can access and read the document content without restriction.

How to install anQi CMS