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 #50

Closed
wants to merge 10 commits into from
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.
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
16 changes: 16 additions & 0 deletions users/userservice/database/user-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
},
password: {
type: String,
required: true,
},
});

const User = mongoose.model('User', userSchema, 'Usuario');

module.exports = User
15 changes: 14 additions & 1 deletion users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express');
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');
const User = require('./user-model')
const User = require('./database/user-model')

const app = express();
const port = 8001;
Expand Down Expand Up @@ -45,6 +45,19 @@ app.post('/adduser', async (req, res) => {
res.status(400).json({ error: error.message });
}});

app.get('/checkuser/:username', async (req, res) => {
try{
const existUser = await User.findOne({ username: req.params.username });
if(existUser){
return res.json({ exists: true });
}else{
return res.json({ exists: false });
}
} catch (error) {
res.status(400).json({ error: error.message });
}
});

const server = app.listen(port, () => {
console.log(`User Service listening at http://localhost:${port}`);
});
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 Down
33 changes: 29 additions & 4 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || '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;
}

const response = await axios.get(`${apiEndpoint}/checkuser/${username}`);
if (response.data.exists) {
setError("Username already exists");
return;
}

await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
Expand All @@ -26,8 +42,8 @@ const AddUser = () => {

return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Add User
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
Create account
</Typography>
<TextField
name="username"
Expand All @@ -46,8 +62,17 @@ const AddUser = () => {
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser}>
Add User
<TextField
name="repeat password"
margin="normal"
fullWidth
label="Repeat Password"
type="password"
value={repPassword}
onChange={(e) => setRepPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser} sx={{ textAlign: 'center' }}>
Register user
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
{error && (
Expand Down
Loading