In AnQi CMS, implement reading levels for specific documents (such as paid documents or member-only content) in the following wayread_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 use AnQi CMS togetherread_levelTo implement document access control.

Understandingread_levelcore mechanism

Anqi CMS provides a namedread_levelThe parameter is an integer value used to indicate the minimum reading level requirement of the document.In simple terms, the higher the number, the higher the reading permission requirements of the document.When we publish a document, we can set one up for itread_levelValue.

At the same time, the user system of Anqi CMS also supports user grouping, and each user group can have a correspondinglevelValue. When a user attempts to access a document that has beenread_levelset, the system will compare the document'sread_levelwith the user group of the currently logged-in userlevel. Only when the user'slevel is greater than or equal toThe document'sread_levelWhen, the user can read the document content normally. If the user's level is insufficient, or the document is also set.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/3means that the user's group level needs to reach or exceed this value to read.
  • price(int, unit is cents):This is the price of the document.
    • If set to0(default value), indicating that the document is free.
    • If set to100means the document price is 1 yuan (100 cents).

For example, if you have a document specifically prepared for VIP members, and your VIP group islevelIs10, then you can name this document'sread_levelis set to10. If 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 Anqi CMS API to determine whether the user has access rights. This usually involves the following steps and interfaces:

  1. Get document details:Firstly, we willarchiveDetailobtain the detailed information of the document through theread_levelandpriceparameters. This is the basis for our judgment.

  2. Determine if the document is paid:If fromarchiveDetailThe document's data returned from the interface,priceThe value is greater than0This means that this is a paid document. In this case, we need to call further.archiveOrderCheckThe interface, pass in the document ID to check if the currently logged-in user has paid for this document.

    • archiveOrderCheckThe interface will returntrueorfalsewhether the user has paid or not.
  3. To get user level information:If the document hasread_levellimitation (i.e."),read_levelgreater than0), we need to obtain the current logged-in user's level. This is usually achieved by combining the following two interfaces:

    • InvokeuserDetailThe interface retrieves the basic information of the currently logged-in user, which includesgroup_id(User's group ID).
    • Then calluserGroupDetailInterface, pass ingroup_idGet the detailed information of the user group to which the user belongs, which will include the user group'slevelValue.
  4. Comprehensive judgment of access privileges:

    • If the document is paid (price > 0):First, checkarchiveOrderCheckThe result is returned. If the payment is not made, the user has no right to read, and the page can prompt the user to purchase. If the payment has been made, continue checking.read_level.
    • If the document has a level restriction (read_level > 0):compare the user's groupleveland the document'sread_level. If the user'slevelis less than the document'sread_level, then the user has no right 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 unregistered users) can read directly.)

Detailed access control to custom fields

The document model (Model) function of AnQi CMS also provides a very powerful option, allowing you to set access permissions in the document.Custom fieldAlso set the access permissions in.moduleDetailIn the model field information returned by the interface, you will see onefollow_levelparameter. If a custom fieldfollow_levelis set totrue, then the content of this field will automatically followread_levelthe restrictions in the document.

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 when the user meets certainread_levelIt is displayed only when a condition is met. When obtaining document details on the front end,archiveDetailThe interface will pass throughextrathe parameters return this custom field data. You just need to parseextrathe data in it, and according to the fields,follow_levelStatus and the user level and document mentioned earlierread_levelLogic to determine whether to display the content of this custom field

Overview of the key steps for front-end implementation

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

  1. When the page loads, througharchiveDetailRequest the document ID or filename to get the detailed information of the document.
  2. Check in the obtained document details,priceandread_levelthe value.
  3. If the user is logged in, get theiruserIdAnd thenuserDetailanduserGroupDetailinterface to get the current user'slevel.
  4. Determine according to 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, the membership upgrade prompt will be displayed, and the document content will be hidden.
    • Otherwise, the user has reading privileges and the document content will be displayed normally.
  5. For the documentextrathe custom field, if itsfollow_levelattribute astrueIf applicable, the same logic should be appliedread_levelCheck the logic to decide whether to display the field content.

By using such a combination, you can flexibly control the reading level of documents in Anqi CMS, whether it is to create paid reading content, exclusive articles for members, or to manage the permissions of specific parts of the document, it can be easily handled.


Frequently Asked Questions (FAQ)

1.read_levelWhat is the default value? When the document'sread_levelmeans when it is 0? read_levelThe default value is0. When the document'sread_levelis set to0When it indicates that the document is open to all users, regardless of whether they are logged in or not, and regardless of the user group they belong to,levelthe number is, they can access and read the document content without any restrictions.

**2. How to use AnQi CMS