cookies to session transition

This commit is contained in:
Dorian Vabre 2021-05-10 15:37:25 +02:00
parent c5dc20b9dc
commit ee4e8dd99f

View File

@ -74,6 +74,8 @@ if ($securekeytocompare != $securekeyreceived) {
exit; exit;
} }
$listofvotes = explode(',', $_SESSION["savevotes"]);
if (GETPOST("votestatus")=="ok") { if (GETPOST("votestatus")=="ok") {
setEventMessage($langs->trans("VoteOk"), 'mesgs'); setEventMessage($langs->trans("VoteOk"), 'mesgs');
} else if (GETPOST("votestatus")=="ko") { } else if (GETPOST("votestatus")=="ko") {
@ -161,7 +163,7 @@ $idvote = GETPOST("vote");
$hashedvote = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'vote'.$idvote); $hashedvote = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'vote'.$idvote);
if (strlen($idvote)) { if (strlen($idvote)) {
if ($_COOKIE['VOTE_SUGGESTED_EVENTS_'.$hashedvote]==1) { if (in_array($hashedvote, $listofvotes)) {
// Has already voted // Has already voted
$votestatus = 'ko'; $votestatus = 'ko';
} else { } else {
@ -172,22 +174,13 @@ if (strlen($idvote)) {
$error++; $error++;
$errmsg .= $conforbooth->error; $errmsg .= $conforbooth->error;
} else { } else {
// Cookie expiration date : start of event, or 30 days if not specified
$startdate = $conforbooth->datep;
if (strlen($startdate)) {
$timeleftbeforestartofevent = $startdate;
} else {
// Cookie duration by default
$timeleftbeforestartofevent = time()+86400*30;
}
// Process to vote // Process to vote
if ($res) { if ($res) {
$conforbooth->num_vote++; $conforbooth->num_vote++;
$resupdate = $conforbooth->update($user); $resupdate = $conforbooth->update($user);
if ($resupdate) { if ($resupdate) {
$votestatus = 'ok'; $votestatus = 'ok';
$res = setcookie('VOTE_SUGGESTED_EVENTS_'.$hashedvote, 1, 0); $_SESSION["savevotes"] = $hashedvote.','.(empty($_SESSION["savevotes"]) ? '' : $_SESSION["savevotes"]); // Save voter
} else { } else {
//Error during update //Error during update
$votestatus = 'err'; $votestatus = 'err';