Remembering last user vote in session

This commit is contained in:
Antonin 2015-11-30 22:23:26 +01:00
parent a219ccdee3
commit 65a753129a
2 changed files with 17 additions and 4 deletions

View File

@ -395,5 +395,6 @@ $smarty->assign('admin', true);
$smarty->assign('hidden', false); $smarty->assign('hidden', false);
$smarty->assign('accessGranted', true); $smarty->assign('accessGranted', true);
$smarty->assign('resultPubliclyVisible', true); $smarty->assign('resultPubliclyVisible', true);
$smarty->assign('editedVoteUniqueId', '');
$smarty->display('studs.tpl'); $smarty->display('studs.tpl');

View File

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