diff --git a/README.md b/README.md index 09f0e4b..8e36fa2 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,16 @@ Run the application through the following API calls: # API Definition +- **Signup Endpoint** + ```http request + POST http://nodeIP:30002/signup + ``` + + ```console + curl --location --request POST 'nodeIP:30002/signup' --form 'username="test"' --form 'password="data"' + ``` + Expected output: User Created successfully + - **Login Endpoint** ```http request POST http://nodeIP:30002/login @@ -271,4 +281,4 @@ To clean up the infrastructure, follow these steps: 1. **Delete the Node Group:** Delete the node group associated with your EKS cluster. -2. **Delete the EKS Cluster:** Once the nodes are deleted, you can proceed to delete the EKS cluster itself. \ No newline at end of file +2. **Delete the EKS Cluster:** Once the nodes are deleted, you can proceed to delete the EKS cluster itself. diff --git a/src/auth-service/server.py b/src/auth-service/server.py index 2355a90..9f1a301 100644 --- a/src/auth-service/server.py +++ b/src/auth-service/server.py @@ -12,7 +12,22 @@ def get_db_connection(): port=5432) return conn - +@server.route('/signup', methods=['POST']) +def signup(): + # auth_table_name = os.getenv('AUTH_TABLE') + auth_table_name = 'auth_user' + if not request.form['username'] or not request.form['password']: + return 'Please enter valid username and password', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + + conn = get_db_connection() + cur = conn.cursor() + query = f"INSERT INTO {auth_table_name} (email, password) VALUES ('{request.form['username']}', '{request.form['password']}');" + res = cur.execute(query) + conn.commit() + + if res is None: + return 'User created successfully' + @server.route('/login', methods=['POST']) def login(): auth_table_name = os.getenv('AUTH_TABLE')