From e180f67c74f0f406254070644d20b0ba84b1420c Mon Sep 17 00:00:00 2001 From: Jack Psaras Date: Tue, 24 Oct 2023 18:35:25 -0400 Subject: [PATCH] made api,lamba func, and connect to create an account page --- lambdafuncs/lambdafunc_signup.py | 47 ++++++++++ src/components/AppHeader.vue | 5 +- src/router/index.js | 10 +- src/views/FetchView.vue | 151 ------------------------------- src/views/LoginPage.vue | 74 +++++++++++++++ src/views/SignUp.vue | 97 ++++++++++++++++++++ 6 files changed, 230 insertions(+), 154 deletions(-) create mode 100644 lambdafuncs/lambdafunc_signup.py delete mode 100644 src/views/FetchView.vue create mode 100644 src/views/LoginPage.vue create mode 100644 src/views/SignUp.vue diff --git a/lambdafuncs/lambdafunc_signup.py b/lambdafuncs/lambdafunc_signup.py new file mode 100644 index 0000000..214fbdb --- /dev/null +++ b/lambdafuncs/lambdafunc_signup.py @@ -0,0 +1,47 @@ +import json +import boto3 + +# Initialize the DynamoDB client +dynamodb = boto3.client('dynamodb') + +# DynamoDB table name +table_name = 'sign_up_DB' # Replace with your DynamoDB table name + +def lambda_handler(event, context): + # Extract the JSON data from the POST request + try: + user_data = event + except Exception as e: + return { + 'statusCode': 400, + 'body': json.dumps({'error': 'Invalid JSON format in the request body'}) + } + + # Check if the required fields are present in the request + if 'username' not in user_data or 'password' not in user_data: + return { + 'statusCode': 401, + 'body': json.dumps({'error': 'Required fields are missing in the request body'}) + } + + # Create an item for the DynamoDB table + item = { + 'username': {'S': user_data['username']}, + 'password': {'S': user_data['password']} + } + + # Put the item into the DynamoDB table + try: + dynamodb.put_item( + TableName=table_name, + Item=item + ) + return { + 'statusCode': 200, + 'body': json.dumps({'message': 'User added successfully'}) + } + except Exception as e: + return { + 'statusCode': 500, + 'body': json.dumps({'error': str(e)}) + } diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue index be86932..92942b2 100644 --- a/src/components/AppHeader.vue +++ b/src/components/AppHeader.vue @@ -8,7 +8,7 @@ Home
  • - Fetch Example + Create an Account