UBOS Community

Discussion on: Налаштування авторизаційного темплейту

Collapse
metareps profile image
montycraig@hotmail.com • Edited on

English Version:

Configuration of Authorization Template

This is a ready-made authentication module that can be used as a starting point for a project to avoid building everything from scratch. It includes an admin panel where new users can be created, their access to pages can be managed, and the ability to modify pages based on user roles. It also provides user registration functionality with email confirmation and password reset functionality.

To begin, create a new UI environment, Node-RED, and a MongoDB database.

Node-RED:

Download the file from the provided repository.

Install the following palettes in the Node-RED environment: node-red-node-email and node-red-node-mongodb.

Import the downloaded file into the Node-RED environment.

Configure the MongoDB node in the Links flow and click deploy.

Configure email sending settings based on the email provider you intend to use.

Fill in the Userid and password in the email node, and update the server if necessary.

If using Gmail, ensure two-factor authentication is set up and create an application password.

Add environment variables (ENV) to the Node-RED environment, storing the links to your Node-RED and UI.

Copy the Node-RED link and click on the question mark button to add a new ENV.

Set the key as nodeUrl and the value as the copied Node-RED link.

Update the ENV.

Add the UI link, ensuring it includes "https://" if it was copied without it.

Store the UI link with the key uiUrl.

Add the UI ENV and update it.

UI:

Add similar ENV variables to the UI environment.

Download the file from the provided repository and import it into the UI.

Open the settings and insert your Node-RED link before "/check_token".

Configure the modules, which represent the pages displayed in the sidebar menu.

In the Parent Modules, list the pages that are initially visible.

In the Child Modules, specify the pages that appear when hovering over the parent element.

Create the parent module "Management" and add three child modules with page names: Modules, AdminRoles, and User Management. Set their positions according to the desired display order.

In Admin Roles, create roles that will have different access to pages.

Create an admin role and provide access to the "Management" module created earlier.

Create a "User" role and assign access to the necessary pages.

Copy the user role ID and paste it into the Node-RED environment in the "registration user" function node.
In User Management, you can create new users, modify their roles, or delete them.

The access token is stored in a cookie named "user_name" and consists of the user's ID and email.

The project settings specify the pages that can be accessed without authentication.

If a user tries to access a page they don't have permission for, they will be redirected to the login page due to the absence of a token.

If no token is present, the user will always be redirected to the login page.

The check_token flow decodes the token and returns information based on it.

The check_token flow builds the menu displayed in the sidebar by retrieving the user's role and generating an object with the accessible pages. The Accordion widget waits for this response to display the pages.