AWTK Open Source Serial Screen Development 9 User and Permission Management

Mondo Technology Updated on 2024-02-20

In the AWTK serial port screen, the built-in user management and permission control model can realize functions such as login, logout, password modification, permission control, user creation, and user deletion without coding.

User management and permission control is a commonly used feature. In industrial software, users are often divided into several different roles, each with different permissions, such as administrator, operator, and maintainer. In the AWTK serial port screen, basic user management and permission control functions are built-in, which can meet common needs. Developers do not need to write, design a good user interface, through data and command binding rules, you can realize user and permission management functions, such as login, logout, change password, permission control, create users, delete users and other functions.

This topic describes the user management and permission control functions in the AWTK serial screen.

1.Factory default user.

In the data file below, you can modify the factory default user and password. Passwords are encrypted using SHA256 and can be generated using the ** tool.

design/default/data/user_manager.csv
For example, the default user in the demo is:

admin|0|8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918|Administrator (default password: admin).
2.Data file format.

Store the username and password in a file in CSV format, one user per row, and each row in the following format:

Username. Chinese is available.

Role. It is used for actual permission control, and it can be used as it is defined. For example, 0 is an administrator, 1 is a table operator, and 2 is a maintainer.

Password. Use SHA256 encryption.

Remark. Chinese is available.

In the following data binding, name represents the user name, role represents the role, password represents the password, and memo represents the remark.

3.User login.

3.1 User login command.

When user management is enabled, the default model provides a command to login.

The login command relies on two properties:

login username The username of the login.

login password.

The login command requires a parameter to specify the target page to which you will be redirected after a successful login.

3.2 Data Binding.

mode=onewaytomodel indicates one-way binding, which can only be bound from the control to the model, mainly because the password in the model is an encrypted hash value, and cannot be reversely bound to the control.

This means that the data input into the control is encrypted with SHA256 and then assigned to the model.

3.3 Command binding.

3.4 Demo Reference Interface.

4.User login status.

4.1 User login status.

When a user logs in successfully, two variables are provided in the default model:

username The username of the login.

userroleThe user role of the login.

UserRole is an integer that allows you to control permissions through UserRole.

4.2 Data Binding.

4.3 Command binding.

For example, a page that can only be accessed by an administrator can be bound with the following command:

For example, if you only need an administrator to execute certain commands, you can use the following command bindings:

4.4 Demo Reference Interface.

Admin interface with full functionality available.

Engineer interface, some features are available.

5.Change your password.

5.1 Change Password command.

When user management is enabled, the default model provides a command to change the password.

The change password command relies on two properties:

change password.

change confirm password to confirm the changed password.

The change password command does not require parameters.

5.2 Data Binding.

5.3 Command binding.

5.4 Demo Reference Interface.

6.User management.

The previous model is the default, and the user management model is the user manager.

6.1 User Management Commands.

When user management is enabled, the user management model (user manager) provides a number of commands.

add to add a user.

remove to delete the user.

edit Edit User.

s**e save the user.

reload the user.

set selected set selected users.

6.2 Data Binding.

6.3 Command binding.

In order to prevent the user from removing the Admin user, you can set the enable property of the Delete button. The binding rules are as follows:

6.4 Demo Reference Interface.

7.Create a user.

The user manager model provides an add command to create a user. If you support creating users, you need to provide an interface for creating users, and the name of the window must be User Manager Add.

The new parameter allows you to set the default data. For example:

user_manager(new=' |1| |');
7.1 Model.

The interface for creating a user has its own model, which represents the currently created user.

It has the following properties:

name represents the username username.

role represents the role role.

password means password.

memo means memo remarks.

It also provides a command to confirm the increase.

add command.

7.2 Data Binding.

7.3 Command binding.

7.4 Demo Reference Interface.

8.Edit the user.

The user manager model provides an edit command that can be used to edit the user. If you support editing users, you need to provide an interface for editing users, and the name of the window must be User Manager Edit.

8.1 Model.

The interface for editing a user has its own model, which represents the currently editing user.

It has the following properties:

name represents the username username.

role represents the role role.

memo means memo remarks.

No additional commands are required.

8.2 Data Binding.

8.3 Command binding.

updateModel=true to update the model, and closewindow=true to close the window.

8.4 Demo Reference Interface.

9.Note.

This project does not write interface-related **, awstudio generates some **frameworks in the src pages directory, these ** are not used, you can delete it or leave it alone, but you can't add it to the compilation.

During actual development, you can refer to the Demo User Manager demo project and modify it on other UI files.

zlg**:

ZLG Developer Community:

For more technical dry goods, please pay attention to "ZLG Zhiyuan Electronics" WeChat***

Related Pages