I am developing a forum, and now I propose this function:
The super administrator must be able to switch some functions of the forum, such as posting, registration, etc.
At my own level, I only think of global variables. , is there an alternative?
The framework is express
Supplement:
The current method that comes to mind is to define some variables globally such as
global.__POST = true //可以发帖
//然后管理页面增加个按钮什么的 请求一个操作
//然后权限审核
...
global.__POST = false //关闭
Then confirm first when the user posts if(global.__POST)
This configuration can be extracted into a public site configuration file, such as adding a
global-config.json
to the project, with the content in the form:Then, add the special API corresponding to the administrator account, and the configuration file can be modified through the administrator API. For general users, the configuration file is read when the page is loaded, and the display logic of related functions is determined based on the parameters persisted in the configuration file.
Users of different levels have different permissions. Many websites have such a design. I don’t quite understand what you mean by global variables. Could you explain your idea in more detail
global is at the application layer and is shared by everyone. You shouldn’t use him to operate it