User-level logic implementation

<< Click to Display Table of Contents >>

Manual > Monitoring system construction guide > Project creation > Creating your own project > User management for your own project (login) > Function explanation >

User-level logic implementation

User Levels

■ User level settings without using the user management function

 

If you are not using the standard user management function, such as for your own project, you can set the user level using the login information of Panel-Interface on Panel Server.

 

(Panel-Interface/Login information)

p_security_0009

 

The level can be set to any integer value.

 

On the login information setting screen, you can assign levels to individual users, or you can register groups and manage them all at once. Setting groups is not required, and if you do not need groups, you can register only users.

 

When a user logs in, the value set for that user's level is stored in the PSUserLevel root property and $USERLEVELBrowser tag. If no group is set, the level value set for the individual user will be used. If a group is registered, the level value registered for the group will be used first.

 

 

 

 

In your own projects, it is up to you to decide how to use user levels.

 

In the following explanation, we will assume that the user names and levels are set as shown in the table below.

 

Username

level

admin

1

senior

10

operator

20

guest

30

 

 

Switching between button operation availability based on user level

The easiest way to automatically switch button operations depending on the user level is to define a bind expression that references $USERLEVELBrowser tag in the binding setting for the Enabled property of the target button.

Here we will introduce a setting example that enables button operations only when the level value is "10 or less" (in other words, only when the user is "admin" or "senior").

 

 

1.First, place a button on the form.

 

p_prj_0296

 

2.Next, open the Binding tab of the button's Enabled property and set the following binding expression:

 

p_prj_0297

 

 

 

 

 

 

 

 

 

$USERLEVEL <= 10

 

 

 

This completes the setup.

 

3.Operation check

 

Run the project and first log in as admin (level 1).

 

When you display a screen with buttons on it, you will see that the buttons are displayed in a usable state, as shown below.

 

p_prj_0298

 

Next, I logged in as guest (level 30). Then, I couldn't operate the buttons, as shown below.

 

p_prj_0299

 

Next, log in as senior (level 10). Then, the buttons will become operable as shown below.

 

p_prj_0298

 

Next, when I logged in with operator (level 20), button operations were disabled as shown below.

 

p_prj_0299

 

 

Referencing the user level from a script

You can also reference the user level from a script. There are two ways to get the level from a script: by directly referencing the PSUserLevel route property, or by calling the AUTH route method.

As an example, we will write a script in the OnMouseUp event of a button and briefly introduce each implementation example.

 

■ Referencing the PSUserLevel root property

 

Here is an example implementation that references the PSUserLevel route property.

 

1.Place a button on the form.

 

p_prj_0296

 

2.Open the button's script page and add a OnMouseUp event.

 

p_prj_0300

 

3.Write a script like the following:

 

p_prj_0301

 

(Description)

event OnMouseUp(button)

{

 if(::PSUserLevel <= 10) {

         ::OpenMsg("Permission OK");

 } else {

         ::OpenMsg("Permission NG");

 }

}

 

❖The code goes between "{" and "}" in the event.

❖All text other than the message box display text should be written in half-width characters.

❖The white space at the beginning of a line is called "indentation." To indent, press the Tab key (you can enter a few half-width spaces, but do not enter full-width spaces).

 

4.Operation check

 

Run the project and log in as admin or senior (i.e. user below level 10).

 

When you click the button, the following message will be displayed:

 

p_prj_0302

 

Next, log in as operator (i.e., a user at level 11 or above) and click the button, and the following will be displayed.

 

p_prj_0303

 

 

■Using the AUTH route method

 

Here is an example of implementation using the AUTH route method. When you call the AUTH method by specifying a number as an argument, it will return True if the number passed is equal to or less than the currently logged-in user level. This allows you to determine whether the current user meets the desired user level.

 

1.Place a button on the form.

 

p_prj_0296

 

2.Open the button's script page and add a OnMouseUp event.

 

p_prj_0300

 

3.Write a script like the following:

 

p_prj_0304

 

(Description)

event OnMouseUp(button)

{

 if(::AUTH(10)) {

         ::OpenMsg("Permission OK");

 } else {

         ::OpenMsg("Permission NG");

 }

}

 

4.Operation check

 

Run the project and log in as admin or senior (i.e. user below level 10).

 

When you click the button, the following message will be displayed:

 

p_prj_0302

 

Next, log in as operator (i.e., a user at level 11 or above) and click the button, and the following will be displayed.

 

p_prj_0303