Skip to content
Snippets Groups Projects
Commit 65a75312 authored by Antonin's avatar Antonin
Browse files

Remembering last user vote in session

parent a219ccde
No related branches found
No related tags found
No related merge requests found
......@@ -395,5 +395,6 @@ $smarty->assign('admin', true);
$smarty->assign('hidden', false);
$smarty->assign('accessGranted', true);
$smarty->assign('resultPubliclyVisible', true);
$smarty->assign('editedVoteUniqueId', '');
$smarty->display('studs.tpl');
......@@ -22,12 +22,19 @@ use Framadate\Services\InputService;
use Framadate\Services\MailService;
use Framadate\Services\NotificationService;
use Framadate\Services\SecurityService;
use Framadate\Services\SessionService;
use Framadate\Message;
use Framadate\Utils;
use Framadate\Editable;
include_once __DIR__ . '/app/inc/init.php';
/* Constantes */
/* ---------- */
const USER_REMEMBER_VOTES_KEY = 'UserVotes';
/* Variables */
/* --------- */
......@@ -40,7 +47,6 @@ $resultPubliclyVisible = true;
$slots = array();
$votes = array();
$comments = array();
$editedVoteUniqueId = null;
/* Services */
/*----------*/
......@@ -51,6 +57,7 @@ $inputService = new InputService();
$mailService = new MailService($config['use_smtp']);
$notificationService = new NotificationService($mailService);
$securityService = new SecurityService();
$sessionService = new SessionService();
/* PAGE */
......@@ -69,6 +76,8 @@ if (!$poll) {
exit;
}
$editedVoteUniqueId = $sessionService->get(USER_REMEMBER_VOTES_KEY, $poll_id, '');
// -------------------------------
// Password verification
// -------------------------------
......@@ -127,8 +136,9 @@ if ($accessGranted) {
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices);
if ($result) {
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
$editedVoteUniqId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqId);
$editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
$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'));
......@@ -154,7 +164,9 @@ if ($accessGranted) {
$result = $pollService->addVote($poll_id, $name, $choices);
if ($result) {
if ($poll->editable == Editable::EDITABLE_BY_OWN) {
$urlEditVote = Utils::getUrlSondage($poll_id, false, $result->uniqId);
$editedVoteUniqueId = $result->uniqId;
$sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId);
$urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
$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', 'Adding the vote succeeded'));
......
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