Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adrian #113

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ed97d36
Subida de prototipos de la interfaz gráfica
AdrianSantamarina Feb 28, 2024
947450a
Creación tabla Usuario
AdrianSantamarina Mar 6, 2024
49fc38c
Creación tabla partida + corrección en tabla usuario
AdrianSantamarina Mar 6, 2024
3bbb82c
Creación tabla historial
AdrianSantamarina Mar 6, 2024
2bb47e1
Arreglo user-model y adicion comprobación contraseña para register
AdrianSantamarina Mar 11, 2024
26a7e08
Usuario se registra ahora en base de datos correcta y corrección AddU…
AdrianSantamarina Mar 11, 2024
bfcc176
Contraseña debe tener 6 caractares al menos
AdrianSantamarina Mar 11, 2024
dfe361a
Arreglo de errores que hacian que no se pudiese añadir un usuario a l…
AdrianSantamarina Mar 11, 2024
38d745e
Adición comprobación nombre de usuario ya existe en register
AdrianSantamarina Mar 11, 2024
c10198b
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es05c into…
AdrianSantamarina Mar 12, 2024
1974061
Corrección register chequee usuario existente + cambios por chakra UI
AdrianSantamarina Mar 12, 2024
ae04284
Arreglos por chakra
AdrianSantamarina Mar 13, 2024
3c206df
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es05c into…
AdrianSantamarina Mar 13, 2024
e39817d
Arreglo, ya funciona chakra en AddUser
AdrianSantamarina Mar 13, 2024
b0b7adc
Terminada pagina AddUser
AdrianSantamarina Mar 13, 2024
0bae4a3
Register arreglado, ya funciona al crear una cuenta
AdrianSantamarina Mar 13, 2024
b388471
Prueba para que pase el test
AdrianSantamarina Mar 14, 2024
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
Binary file added docs/images/game_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/home_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/login_Page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/ranking_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/register_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,652 changes: 3,651 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"framer-motion": "^11.0.12"
}
}
29 changes: 29 additions & 0 deletions users/userservice/database/game-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');
const User = require('./user-model');

const gameSchema = new mongoose.Schema({
correct_answers: {
type: Number,
required: true,
},
failed_answers: {
type: Number,
required: true,
},
punctuation: {
type: Number,
required: true,
},
time: {
type: TimeStamp,
required: true,
},
user: {
type: User,
required: true,
},
});

const Game = mongoose.model('Game', gameSchema, 'Game');

module.exports = Game
28 changes: 28 additions & 0 deletions users/userservice/database/history-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const mongoose = require('mongoose');

const historySchema = new mongoose.Schema({
total_correct_answers: {
type: Number,
required: true,
},
total_failed_answers: {
type: Number,
required: true,
},
total_punctuation: {
type: Number,
required: true,
},
total_time: {
type: TimeStamp,
required: true,
},
user: {
type: User,
required: true,
},
});

const History = mongoose.model('History', historySchema, 'History');

module.exports = History
1 change: 1 addition & 0 deletions users/userservice/package-lock.json

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

13 changes: 9 additions & 4 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ app.post('/adduser', async (req, res) => {
// Encrypt the password before saving it
const hashedPassword = await bcrypt.hash(req.body.password, 10);

const newUser = new User({
const user = await User.findOne({ username: req.body.username });
if (user) {
res.status(401).json({ error: error.message });
}else{
const newUser = new User({
username: req.body.username,
password: hashedPassword,
});
});

await newUser.save();
res.json(newUser);
await newUser.save();
res.json(newUser);
}
} catch (error) {
res.status(400).json({ error: error.message });
}});
Expand Down
40 changes: 12 additions & 28 deletions webapp/package-lock.json

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

3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"private": true,
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.15.3",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"axios": "^1.6.5",
"framer-motion": "^11.0.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
10 changes: 8 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function App() {
const [showLogin, setShowLogin] = useState(true);
const [showGame, setShowGame] = useState(false); // Nuevo estado para controlar si se muestra el juego
const [showWelcomeMessage, setShowWelcomeMessage] = useState(true); // Estado para controlar la visibilidad del mensaje de bienvenida y los enlaces
const [showAddUser, setShowAddUser] = useState(false);


const handleToggleView = () => {
Expand All @@ -27,6 +28,7 @@ function App() {
setShowLogin(false);
setShowGame(true);
setShowWelcomeMessage(false);
setShowAddUser(false);
};

return (
Expand All @@ -35,7 +37,7 @@ function App() {
{/* Mostrar el mensaje de bienvenida y los enlaces solo si showWelcomeMessage es true */}
{showWelcomeMessage && (
<Typography component="h1" variant="h5" align="center" sx={{ marginTop: 2 }}>
Welcome to the 2024 edition of the Software Architecture course
Welcome to Wiq-es05
<Typography component="div" align="center" sx={{ marginTop: 2 }}>
{showLogin ? (
<Link name="gotoregister" component="button" variant="body2" onClick={handleToggleView}>
Expand All @@ -51,7 +53,11 @@ function App() {
)}

{showLogin && <Login startGame={startGame} />}
{!showLogin && !showGame && <AddUser />}
{!showLogin && !showGame && (
<ChakraProvider>
<AddUser />
</ChakraProvider>
)}
{showGame && (
<ChakraProvider>
<Game />
Expand Down
95 changes: 64 additions & 31 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
// src/components/AddUser.js
import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';
import { Box, Center, Text, Input, Button, FormControl, FormLabel, Alert } from '@chakra-ui/react';
import { QuestionArea } from './QuestionArea';

const apiEndpoint = process.env.REACT_APP_API_URI || 'http://localhost:8000';

const AddUser = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [repPassword, setRepPassword] = useState('');
const [error, setError] = useState('');
const [openSnackbar, setOpenSnackbar] = useState(false);

const addUser = async () => {
try {
if(password.length < 6){
setError("Password must have at least 6 characters");
return;
}
if(password !== repPassword){
setError("Passwords don't match");
return;
}

await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
if (error.response && error.response.data && error.response.data.error) {
setError(error.response.data.error);
} else {
setError("An unexpected error occurred");
}
}
};

Expand All @@ -25,35 +40,53 @@ const AddUser = () => {
};

return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Add User
</Typography>
<TextField
name="username"
margin="normal"
fullWidth
label="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<TextField
name="password"
margin="normal"
fullWidth
label="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser}>
Add User
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
</Container>
<Center h="100vh" w="100vw" bgGradient="linear(to-t, #08313A, #107869)">
<Box p="100" w="100%" h="35%" maxW="md" display="flex" flexDirection="column" justifyContent="center" alignItems="center" gap={14} bg="white">
<Text as="b" fontSize="3xl" mb="4">
Create account
</Text>
<FormControl>
<FormLabel>Username</FormLabel>
<Input
name="username"
margin="normal"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<FormLabel>Password</FormLabel>
<Input
name="password"
margin="normal"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<FormLabel>Repeat Password</FormLabel>
<Input
name="repeat password"
margin="normal"
type="password"
value={repPassword}
onChange={(e) => setRepPassword(e.target.value)}
/>
</FormControl>
<Button variant="solid" onClick={addUser} textAlign="center"
color="white" bgGradient="linear(to-t, #08313A, #107869)" size="lg">
Add user
</Button>
{openSnackbar && (
<Alert status="success" marginTop={2} onClose={handleCloseSnackbar}>
User added successfully
</Alert>
)}
{/* Alerta para errores */}
{error && (
<Alert status="error" marginTop={2} onClose={() => setError('')}>
Error: {error}
</Alert>
)}
</Box>
</Center>
);
};

Expand Down
Empty file.
Loading