Commit 1ec8db4c authored by Olivier PEREZ's avatar Olivier PEREZ
Browse files

Check if vote name is already used + Fix missing key

parent 7c265c57
......@@ -74,4 +74,17 @@ class VoteRepository extends AbstractRepository {
return $prepared->execute([$choices, $name, $poll_id, $vote_id]);
}
/**
* Check if name is already used for the given poll.
*
* @param int $poll_id ID of the poll
* @param string $name Name of the vote
* @return bool true if vote already exists
*/
public function existsByPollIdAndName($poll_id, $name) {
$prepared = $this->prepare('SELECT 1 FROM `' . Utils::table('vote') . '` WHERE poll_id = ? AND name = ?');
$prepared->execute(array($poll_id, $name));
return $prepared->rowCount() > 0;
}
}
......@@ -75,6 +75,10 @@ class PollService {
}
function addVote($poll_id, $name, $choices) {
if ($this->voteRepository->existsByPollIdAndName($poll_id, $name)) {
return false;
}
$choices = implode($choices);
$token = $this->random(16);
return $this->voteRepository->insert($poll_id, $name, $choices, $token);
......
......@@ -155,7 +155,8 @@
"The poll is expired, it will be deleted soon.": "Die Umfrage ist abgelaufen, es wird bald gelöscht werden.",
"Deletion date:": "Löschdatum:",
"Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:": "DE_Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! ",
"Update vote succeeded": "Update Abstimmung gelungen"
"Update vote succeeded": "Update Abstimmung gelungen",
"Adding the vote succeeded": "Hinzufügen der Abstimmung war erfolgreich"
},
"adminstuds": {
"As poll administrator, you can change all the lines of this poll with this button": "Als Administrator der Umfrage, können Sie alle Zeilen der Umfrage über diesen Button ändern",
......
......@@ -155,7 +155,8 @@
"The poll is expired, it will be deleted soon.": "The poll is expired, it will be deleted soon.",
"Deletion date:": "Deletion date:",
"Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:": "Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote.",
"Update vote succeeded": "Update vote succeeded"
"Update vote succeeded": "Update vote succeeded",
"Adding the vote succeeded": "Adding the vote succeeded"
},
"adminstuds": {
"As poll administrator, you can change all the lines of this poll with this button": "As poll administrator, you can change all the lines of this poll with this button",
......
......@@ -155,7 +155,8 @@
"The poll is expired, it will be deleted soon.": "ES_Le sondage a expiré, il sera bientôt supprimé.",
"Deletion date:": "ES_Date de suppression :",
"Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:": "ES_Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! ",
"Update vote succeeded": "ES_Mise à jour du vote réussi"
"Update vote succeeded": "ES_Mise à jour du vote réussi",
"Adding the vote succeeded": "ES_Ajout du vote réussi"
},
"adminstuds": {
"As poll administrator, you can change all the lines of this poll with this button": "En calidad de administrador, Usted puede cambiar todas la líneas de este encuesta con este botón",
......
......@@ -155,7 +155,8 @@
"The poll is expired, it will be deleted soon.": "Le sondage a expiré, il sera bientôt supprimé.",
"Deletion date:": "Date de suppression :",
"Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:": "Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! ",
"Update vote succeeded": "Mise à jour du vote réussi"
"Update vote succeeded": "Mise à jour du vote réussi",
"Adding the vote succeeded": "Ajout du vote réussi"
},
"adminstuds": {
"As poll administrator, you can change all the lines of this poll with this button": "En tant qu'administrateur, vous pouvez modifier toutes les lignes de ce sondage avec ce bouton",
......
......@@ -155,7 +155,8 @@
"The poll is expired, it will be deleted soon.": "Il sondaggio è scaduto, sarà presto rimosso.",
"Deletion date:": "Data di cancellazione:",
"Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:": "Il tuo voto è stato preso in considerazione, ma attenzione: questa indagine non consente la modifica del voto con il seguente link personalizzato; tenerlo al sicuro!",
"Update vote succeeded": "Aggiornamento del voto di successo"
"Update vote succeeded": "Aggiornamento del voto di successo",
"Adding the vote succeeded": "L'aggiunta del voto ha avuto successo"
},
"adminstuds": {
"As poll administrator, you can change all the lines of this poll with this button": "Essendo l'amministratore, potete modificare tutte le righe di questo sondaggio con questo pulsante",
......
......@@ -163,11 +163,11 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$urlEditVote = Utils::getUrlSondage($poll_id, false, $result->uniqId);
$message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
} else {
$message = new Message('success', __('studs', 'Update vote succeeded'));
$message = new Message('success', __('studs', 'Adding the vote succeeded'));
}
sendUpdateNotification($poll, $mailService, $name, ADD_VOTE);
} else {
$message = new Message('danger', __('Error', 'Update vote failed'));
$message = new Message('danger', __('Error', 'Adding vote failed'));
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment