Skip to content
Snippets Groups Projects
Commit 62497453 authored by Richard Fernando Heise Ferreira's avatar Richard Fernando Heise Ferreira Committed by Stephanie Briere Americo
Browse files

Issue #29: User can't answer a form twice

parent 4e193cd1
No related branches found
No related tags found
2 merge requests!58Version 1.1,!54Issue #53: Fix password info
...@@ -153,6 +153,7 @@ function AnwserForm() { ...@@ -153,6 +153,7 @@ function AnwserForm() {
const res = await api const res = await api
.post(`/answer/${id}`, backendTranslation()) .post(`/answer/${id}`, backendTranslation())
.then(function(res) { .then(function(res) {
setCookie("answerForm", id, 92);
alert("Formulário respondido!"); alert("Formulário respondido!");
}) })
.catch(error => { .catch(error => {
...@@ -205,6 +206,7 @@ function AnwserForm() { ...@@ -205,6 +206,7 @@ function AnwserForm() {
const res = await api const res = await api
.get(`/form/${id}`) .get(`/form/${id}`)
.then(function(res) { .then(function(res) {
checkCookie(id);
setFormData(res.data); setFormData(res.data);
mapInputs(res.data); mapInputs(res.data);
}) })
...@@ -223,6 +225,38 @@ function AnwserForm() { ...@@ -223,6 +225,38 @@ function AnwserForm() {
}); });
} }
function setCookie(cookieName, cookieValue, expirationsDays) {
var date = new Date();
date.setTime(date.getTime() + expirationsDays * 60 * 60 * 24 * 1000);
var expires = "expires=" + date.toUTCString();
document.cookie =
cookieName + "=" + cookieValue + ";" + expires + ";path=/";
}
function getCookie(cookieName) {
var name = cookieName + "=";
var ca = document.cookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie(id) {
var answer = getCookie("answerForm");
if (answer == id) {
alert("Você já respondeu esse formulário! ");
let path = `/signin`;
history.push(path);
}
}
/** First thing the page does is getting the form from the API. */ /** First thing the page does is getting the form from the API. */
useEffect(() => { useEffect(() => {
getForm(id); getForm(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment