Skip to content

Commit

Permalink
Merge pull request #124 from Arquisoft/120-play-as-a-guest-functionality
Browse files Browse the repository at this point in the history
120 play as a guest functionality
  • Loading branch information
lauratbg authored Apr 25, 2024
2 parents 5faed58 + 8479e47 commit e3c459d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ app.post('/adduser', async (req, res) => {
}
});

app.get('/questions', verifyToken, async (req, res) => {
app.get('/questions', async (req, res) => {
try {

// Forward the question request to the quetion service
Expand Down Expand Up @@ -101,7 +101,7 @@ app.get('/questions/:lang/:amount', verifyToken, async (req, res) => {
}
});

app.get('/questions/:lang', verifyToken, async (req, res) => {
app.get('/questions/:lang', async (req, res) => {
try {
if(!validateLang(req.params.lang.toString()))
res.status(400).json({ error: 'Wrong values given' });
Expand Down
Binary file added webapp/public/game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function App() {
<Route path="/instructions" element={<Instructions />} />
<Route path="/addUser" element={isLoggedIn ? <GameMenu /> : <AddUser />} />
<Route path="/menu" element={isLoggedIn ? <GameMenu /> : <Login /> } />
<Route path="/questions" element={isLoggedIn ? <QuestionView /> : <Login />} />
<Route path="/questions" element={ <QuestionView />} />
<Route path="/historical" element={isLoggedIn ? <HistoricalView /> : <Login />} />
<Route path="/configurator" element={isLoggedIn ? <GameConfigurator /> : <Login />}/>
<Route path="/ranking" element={isLoggedIn ? <RankingView /> : <Login />} />
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function Home() {
<label htmlFor="toggleClose" title={t("home.clickClose")}></label>
<b>
W
<Link to="/instructions" title={t("home.how_to_play")}>
<img src="/instrucciones.png" alt="Instructions" style={{ width: "100%", height: "100%" }} />
<Link to="/questions" title={t("home.game")}>
<img src="/game.png" alt="Game" style={{ width: "100%", height: "100%" }} />
</Link>
</b>
<b>
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/Home/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('Home component', () => {
// Click toggle open button
fireEvent.click(screen.getByTitle("home.clickOpen"));

// Icons of instructions, login and signup must be shown
expect(screen.getByAltText('Instructions')).toBeVisible();
// Icons of play as guest, login and signup must be shown
expect(screen.getByAltText('Game')).toBeVisible();
expect(screen.getByAltText('Login')).toBeVisible();
expect(screen.getByAltText('Add user')).toBeVisible();

Expand Down
8 changes: 5 additions & 3 deletions webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import BackButtonToGameMenu from '../fragments/BackButtonToGameMenu';
const creationHistoricalRecord = new CreationHistoricalRecord();
const questionGenerator = new QuestionGenerator();
var points = 0;
var playAsGuestUsername = "Play as Guest" //Wont be ever used as it has spaces
var playAsGuestToken = " "
function QuestionView({type= "COMPETITIVE", amount=5}){
const [numQuestion, setnumQuestion] = useState(-1);
const [questions, setQuestions] = useState(null);
const[t, i18n] = useTranslation("global");
const cookie = JSON.parse(Cookies.get('user'))
const cookie = JSON.parse(Cookies.get('user')??JSON.stringify({username : playAsGuestUsername, token : playAsGuestToken}))
const [audio] = useState(new Audio('/tictac.mp3'));


const generateQuestions = async (numQuestion) => {
if (numQuestion < 0) {
try {

var generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token);
setQuestions(generatedQuestions);
points=0;
Expand Down Expand Up @@ -111,7 +112,8 @@ function QuestionView({type= "COMPETITIVE", amount=5}){
creationHistoricalRecord.setCompetitive(type === 'COMPETITIVE');
creationHistoricalRecord.setDate(Date.now());
creationHistoricalRecord.setPoints(points);
creationHistoricalRecord.sendRecord(cookie.username, cookie.token);
if(cookie.username !== playAsGuestUsername)
creationHistoricalRecord.sendRecord(cookie.username, cookie.token);
}
}, 1000);

Expand Down
3 changes: 2 additions & 1 deletion webapp/src/translations/en/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"msg1": "Welcome to the knowledge challenge! Get ready to test your mind and demonstrate your skills. In this exciting game, you will face a series of questions that will test your knowledge on a variety of topics.",
"msg2": "So go ahead, prove that you are the master of questions! Are you ready to accept the challenge?",
"clickOpen": "Click to continue",
"clickClose": "Click to close"
"clickClose": "Click to close",
"game":"Play as a guest"
},

"navBar": {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/translations/es/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"msg1": "Bienvenido al desafío de conocimientos! Prepárate para poner a prueba tu mente y demostrar tus habilidades. En este emocionante juego, te enfrentarás a una serie de preguntas que pondrán a prueba tu conocimiento en una variedad de temas.",
"msg2": "¡Así que adelante, demuestra que eres el maestro de las preguntas! ¿Estás listo para aceptar el desafío?",
"clickOpen": "Haz click para continuar",
"clickClose": "Haz click para cerrar"
"clickClose": "Haz click para cerrar",
"game":"Juega como invitado"

},

Expand Down

0 comments on commit e3c459d

Please sign in to comment.