Skip to content

Commit

Permalink
Merge branch 'bug-fixes' of https://github.com/oslabs-beta/LambdaPulse
Browse files Browse the repository at this point in the history
…into settingspage
  • Loading branch information
bryentsariwati committed Apr 27, 2023
2 parents cf8dc9e + 761c8a2 commit 1335281
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ DEV INSTALLATION INSTRUCTIONS:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
USER_ROLE_ARN

-also a separate .env in client folder, setup VITE_CAPTCHA_KEY = "google captchav2 key"
5) install redis-server via apt/brew/etc
6) npm run fulldev

Expand Down
20 changes: 19 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"dependencies": {
"axios": "^1.3.5",
"d3": "^7.8.4",
"dotenv": "^16.0.3",
"react": "^18.2.0",
"react-d3-tree": "^3.5.1",
"react-data-table-component": "^7.5.3",
"react-dom": "^18.2.0",
"react-minimal-pie-chart": "^8.4.0",
"react-router-dom": "^6.10.0"
"react-router-dom": "^6.10.0",
"reaptcha": "^1.12.1"
},
"devDependencies": {
"@types/react": "^18.0.28",
Expand Down
16 changes: 15 additions & 1 deletion client/src/pages/Signup.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import NavBar from '../components/NavBar';
import Reaptcha from "reaptcha";
import './Login.css';


const Signup = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [fullName, setFulltName] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [captcha, setCaptcha] = useState('')

const navigate = useNavigate();

Expand All @@ -17,11 +20,15 @@ const Signup = () => {
setErrorMessage('Passwords do not match');
return;
}
if (captcha !== "passed") {
setErrorMessage('Captcha required')
return;
}

const userData = {
email,
password,
full_name: fullName,
fullName,
};
console.log(userData);
fetch('/createUser', {
Expand Down Expand Up @@ -89,6 +96,13 @@ const Signup = () => {
required
onChange={(e) => setConfirmPassword(e.target.value)}
/>
<div>
<Reaptcha
sitekey={captchaKey}
onVerify={()=>setCaptcha("passed")}
required
/>
</div>
<button className='login-btn' type='submit'>
Sign Up
</button>
Expand Down
5 changes: 5 additions & 0 deletions client/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
dotenv.config();

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -15,4 +17,7 @@ export default defineConfig({
},
},
plugins: [react()],
define: {
captchaKey:`"${process.env.VITE_CAPTCHA_KEY}"`
}
});
12 changes: 10 additions & 2 deletions server/controllers/awsCredentialsController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { AssumeRoleCommand } = require('@aws-sdk/client-sts');
const { stsClient } = require('../db.config.js');
const { query } = require('../db.config.js');

const awsCredentialsController = {};

Expand All @@ -9,7 +10,14 @@ awsCredentialsController.getCredentials = async (req, res, next) => {
return next();
}
console.log('Received creds request at ' + Date.now());
const userRoleArn = process.env.USER_ROLE_ARN;
//use this: res.locals.userId to find user's ARN
//SELECT user.role_ARN where user.id = res.locals.userID
const roleResult = await query('SELECT role_arn FROM users WHERE _id = $1 ;', [res.locals.userId])
console.log('this is roleResult in AWS credentials', roleResult)
const getRole = roleResult.rows.map(row => row.role_arn)[0]
console.log('this is getRole in AWS credentials', getRole)

const userRoleArn = getRole;
console.log('req body: ', req.body);

if (!userRoleArn) {
Expand All @@ -18,7 +26,7 @@ awsCredentialsController.getCredentials = async (req, res, next) => {

const assumeRoleParams = {
RoleArn: userRoleArn,
RoleSessionName: 'TestSession',
RoleSessionName: 'lambdaPulseSession',
};

try {
Expand Down
8 changes: 4 additions & 4 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const jwt = require('jsonwebtoken');
// Creation of user using PostgresSQL

const createUser = async (req, res, next) => {
const { full_name, email, password } = req.body;
const { fullName, email, password } = req.body;
console.log('in create user');
console.log(full_name, email, password);
try {
const getResult = await query('SELECT * FROM users WHERE email = $1', [
email,
Expand All @@ -20,9 +19,10 @@ const createUser = async (req, res, next) => {

const result = await query(
'INSERT INTO users (full_name, email, password) VALUES ($1, $2, $3) RETURNING _id',
[full_name, email, hashedPassword]
[fullName, email, hashedPassword]
);
const userId = result.rows[0].id;
console.log('result.rows[0].id', result.rows[0]._id);
const userId = result.rows[0]._id;

console.log('user created successfully');
res.locals.userId = userId;
Expand Down
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ app.post('/verifyUser', userController.verifyUser, jwtController.createJwt, (req
res.sendStatus(200);
});

app.get('/logout', userController.logout);
app.get('/logout',redisController.clearTraces, userController.logout);

app.post('/setLogs', redisController.setLogs, (req, res) => {
//successful login
Expand Down

0 comments on commit 1335281

Please sign in to comment.