This project demonstrates a simple user management system implemented in C using the C_STD
framework. It handles user creation, storage in a PostgreSQL database, and serialization to JSON. The code is designed to be easily extendable and showcases some of the key features of the C_STD
framework.
- User Creation: Each user is assigned an ID, name, email, and registration timestamp.
- Database Integration: Users are stored in a PostgreSQL database.
- Vector Container: Users are maintained in a vector container for easy management.
- JSON Serialization: Users can be serialized to JSON for storage or transmission.
- Time Management: Registration time is captured and formatted using the
C_STD
time module.
- GCC compiler (ensure it's added to your system's PATH).
- CMake for building the project.
- OpenSSL (for SSL/TLS functionality, if needed).
- Linux Users: Ensure you have development libraries installed:
sudo apt-get install libssl-dev
Ensure you have the following installed on your system:
- C compiler (e.g., GCC)
- PostgreSQL database server
C_STD
framework (ensure all required modules are included)libpq
(PostgreSQL C library)- CMake for project configuration and build
-
Install PostgreSQL on your machine if it's not already installed.
-
Create a Database:
CREATE DATABASE test;
-
Create the Users Table:
CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(100), email VARCHAR(100), time_registered TIMESTAMP );
-
Clone the Repository:
git clone https://github.com/KaisenAmin/User-Management-C_std.git cd User-Management-C_std
-
Create and Navigate to the Build Directory:
mkdir build cd build
-
Clean Previous Builds (optional): Before starting a new build, it's a good practice to clean previous build files:
rm -rf CMakeCache.txt CMakeFiles
-
Configure the Project: Use CMake to configure the project with GCC as the compiler:
cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
-
Compile the Code:
cmake --build .
-
Run the Program:
make run
If everything is set up correctly, the program will run, connect to the PostgreSQL database, and perform the user management tasks.
The program will:
- Attempt to connect to the PostgreSQL database.
- Create a new user with random details.
- Store the user in the PostgreSQL database.
- Display all users currently in the vector container.
- Serialize the vector of users to JSON and print it to the console.
Time is 2024-08-21
Data in Vector Container of Users
Id : 4, Name : User 123, Email : [email protected]
Json Serialized Data is
[
{
"id": 4,
"name": "User 123",
"email": "[email protected]",
"time_registered": "2024-08-21T15:23:45"
}
]
This project is licensed under the MIT License - see the LICENSE file for details.
This project is built using the C_STD
framework, a custom C library aimed at simplifying and standardizing common tasks in C programming.