Thursday, April 30, 2020

User management application using Node.js and Redis

Here I created a user management application using Redis and Node.js. Here we can simply add and search through user detail records.

The application consists of a few components. There is the main app.js file which controls much of the application. And I used express for Node.js with handlebars to add users, create details and search through the users. 

In this adduser.handlebars file I create the "POST" method with an action that will send the information below in a post to  /user/add which will create the new user in Redis.



Next in the details.handlebars file below I set everything up to handle the display of the records that are retrieved from Redis.



Then I have a searchusers.handlebars file which handles the search functionality.



The main.handlebars file handles the HTML output and is quite similar to any other HTML page with the interesting differentiation of how the body content is handled. The triple curly brackets tell handlebars to display the information from Redis within this container.


And now that I've gone over the files that connect with the main app.js file perhaps it will help clear everything up a bit to focus on how the directives are being initiated. Below I am showing the different constructor variables I setup. This is a Node.js app using express, express-handlebars and I set up a few other parameters that are required.



With everything setup it's simple to create the Redis client from here.


I then set the port and initialize express within the app. I also created some middleware for the body parser, a view engine, setup the MethodOverride function. And then this next part I found interesting because here I am taking the user input from the HTML page and feeding it to Redis in a similar manner as if I as the admin were manually adding users from the command line. Next here is how the search processing is handled. The application sends post request to /user/search and if the object does not exit an error message saying "User does not exist" is returned. In the case that the object exists the instructions below are to render or to show the users the details for a particular obj. In this case I am just searching by user ID's, but this can be run with any of the fields but a user ID is usually the most unique. There may be two John Smiths within the system but there can only be one user001 and one user002. 





Next in the "Add User" process I setup the application to create a post request to /user/add with the fields the user is required to enter: id, first_name, last_name, email and phone number. If there is an error it is logged to the console. If everything posts correctly then a new user is created in Redis and the user is redirected to the home page.





Now I can search through the records and add users from this Redis/Node.js application that I can access from the internet.






No comments:

Post a Comment

Automated Exploitation of a Bluetooth vulnerability that leads to 0-click code execution

This blog post covers an interesting vulnerability that was just discovered earlier this year and an open source free tool that was created ...