Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 79 additions & 8 deletions aws/src/lambdas/signup/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const handler = async (event) => {
console.log("Event: ", JSON.stringify(event, null, 2));
const mysql = require('mysql2');

const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
};

module.exports.handler = async (event) => {
const httpMethod = event.requestContext.http.method;
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
console.log("Event: ", JSON.stringify(event, null, 2));

let request_body;
if (event.body) {
request_body = JSON.parse(event.body);
} else {
console.log("No body found");
return {
statusCode: 400,
body: JSON.stringify({ message: "No body found" }),
};
}

const { uuid, enc_uuid, enc_name, email, enc_phone, enc_answers } = request_body;
const time_creation = new Date().toISOString();

let connection;

try {
connection = mysql.createConnection(dbConfig).promise();

const [existing] = await connection.execute(
'SELECT uuid FROM users WHERE enc_email = ?',
[email]
);

if (existing.length > 0) {
return {
statusCode: 200,
body: JSON.stringify({
message: "Hello from signup lambda!"
}),
body: JSON.stringify({ message: "User already signed up." }),
};
}

await connection.execute(
'INSERT INTO users (uuid, enc_uuid, enc_name, enc_email, enc_phone_num, enc_time_creation) VALUES (?, ?, ?, ?, ?, ?)',
[uuid, enc_uuid, enc_name, email, enc_phone, time_creation]
);

await connection.execute(
'INSERT INTO sec_questions (uuid, enc_uuid, enc_question1, enc_question2, enc_question3, enc_question4, enc_question5, enc_question6, enc_question7, enc_question8, enc_question9, enc_question10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[uuid, enc_uuid, ...enc_answers]
);

return {
statusCode: 200,
body: JSON.stringify({ message: "User and security questions inserted successfully!" }),
};

} catch (error) {
console.error("Database error:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Database operation failed", error: error.message }),
};

} finally {
if (connection) {
await connection.end();
}
}
};
module.exports = { handler };
13 changes: 0 additions & 13 deletions aws/src/lambdas/signup/index.ts

This file was deleted.

17 changes: 12 additions & 5 deletions aws/src/lambdas/signup/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"devDependencies": {
"@types/aws-lambda": "^8.10.147",
"typescript": "^5.7.3"
"name": "lambda",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cookie": "^1.0.2"
"mysql2": "^3.14.0"
}
}
}

Binary file removed aws/src/lambdas/signup/signup.zip
Binary file not shown.
11 changes: 0 additions & 11 deletions aws/src/lambdas/signup/tsconfig.json

This file was deleted.

20 changes: 18 additions & 2 deletions extension/src/hashpass/app/hashpass_signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { TextField, Button, Card, CardContent, Typography, Box, CircularProgress } from '@mui/material';
import { encrypt } from '../security_components/tools/AES_tool';
import { v4 as uuidv4 } from 'uuid';

const securityQuestions = [
"What is your favorite color?",
Expand Down Expand Up @@ -66,10 +68,24 @@ const handleSubmit = async (e: React.FormEvent) => {
}

try {
const res = await fetch('/api/user-signup', {
const uuid = uuidv4();
const enc_uuid = await encrypt(uuid, formData.passphrase);
const enc_name = await encrypt(formData.name, formData.passphrase);
const enc_phone = await encrypt(formData.phone, formData.passphrase);
const enc_answers = await Promise.all(formData.securityAnswers.map((answer: string) => encrypt(answer, formData.passphrase)));
const dataToSend = {
uuid: uuid,
enc_uuid: enc_uuid,
enc_name: enc_name,
email: formData.email,
enc_phone: enc_phone,
enc_answers: enc_answers,
}

const res = await fetch('https://8fy84busdk.execute-api.us-east-1.amazonaws.com/API/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
body: JSON.stringify(dataToSend),
});

const data = await res.json();
Expand Down