diff --git a/action/send_edit_link_by_email_action.php b/action/send_edit_link_by_email_action.php new file mode 100644 index 0000000..eff06fd --- /dev/null +++ b/action/send_edit_link_by_email_action.php @@ -0,0 +1,98 @@ + ['regexp' => POLL_REGEX]]); + $poll = $pollService->findById($poll_id); +} + +$token = $sessionService->get("Common", SESSION_EDIT_LINK_TOKEN); +$token_form_value = empty($_POST['token']) ? null : $_POST['token']; +$editedVoteUniqueId = filter_input(INPUT_POST, 'editedVoteUniqueId', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); +if (is_null($poll) || $config['use_smtp'] == false || is_null($token) || is_null($token_form_value) + || !$token->check($token_form_value) || is_null($editedVoteUniqueId)) { + $message = new Message('error', __('Error', 'Something is going wrong...')); +} + +if (is_null($message)) { + $email = $mailService->isValidEmail($_POST['email']); + if (is_null($email)) { + $message = new Message('error', __('EditLink', 'The email address is not correct.')); + } +} + +if (is_null($message)) { + $time = $sessionService->get("Common", SESSION_EDIT_LINK_TIME); + + if (!empty($time)) { + $remainingTime = TIME_EDIT_LINK_EMAIL - (time() - $time); + + if ($remainingTime > 0) { + $message = new Message('error', sprintf(__('EditLink', 'Please wait %d seconds before we can send an email to you then try again.'), $remainingTime)); + } + } +} + + +if (is_null($message)) { + $url = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId); + + $smarty->assign('poll', $poll); + $smarty->assign('poll_id', $poll_id); + $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); + $body = $smarty->fetch('mail/remember_edit_link.tpl'); + + $subject = '[' . NOMAPPLICATION . ']['.__('EditLink', 'REMINDER').'] '.sprintf(__('EditLink', 'Edit link for poll "%s"'), $poll->title); + + //$mailService->send($email, $subject, $body); + $sessionService->remove("Common", SESSION_EDIT_LINK_TOKEN); + $sessionService->set("Common", SESSION_EDIT_LINK_TIME, time()); + + $message = new Message('success', __('EditLink', 'Your reminder has been successfully sent!')); + $result = true; +} + + +error_reporting(E_ALL & ~E_NOTICE); +$smarty->error_reporting = E_ALL & ~E_NOTICE; + +$response = array('result' => $result, 'message' => $message, '$email'=> $email, '$subject'=>$subject, '$body'=>$body); + + +echo json_encode($response); \ No newline at end of file diff --git a/app/inc/config.template.php b/app/inc/config.template.php index 2b60ade..bcbd21b 100644 --- a/app/inc/config.template.php +++ b/app/inc/config.template.php @@ -77,6 +77,9 @@ const PURGE_DELAY = 60; // Max slots per poll const MAX_SLOTS_PER_POLL = 366; +// Number of seconds before we allow to resend an "Remember Edit Link" email. +const TIME_EDIT_LINK_EMAIL = 60; + // Config $config = [ /* general config */ diff --git a/app/inc/constants.php b/app/inc/constants.php index 1d58299..9782464 100644 --- a/app/inc/constants.php +++ b/app/inc/constants.php @@ -30,5 +30,9 @@ const EDITABLE_CHOICE_REGEX = '/^[0-2]$/'; const BASE64_REGEX = '/^[A-Za-z0-9]+$/'; const MD5_REGEX = '/^[A-Fa-f0-9]{32}$/'; +// Session constants +const SESSION_EDIT_LINK_TOKEN = 'EditLinkToken'; +const SESSION_EDIT_LINK_TIME = "EditLinkMail"; + // CSRF (300s = 5min) const TOKEN_TIME = 300; diff --git a/studs.php b/studs.php index 16c76b3..4b69f65 100644 --- a/studs.php +++ b/studs.php @@ -28,6 +28,7 @@ use Framadate\Services\SessionService; use Framadate\Message; use Framadate\Utils; use Framadate\Editable; +use Framadate\Security\Token; include_once __DIR__ . '/app/inc/init.php'; @@ -147,6 +148,15 @@ if ($accessGranted) { $urlEditVote, __('Poll results', 'Edit the line:').' '.$name, 'glyphicon-pencil'); + if ($config['use_smtp']) { + $token = new Token(); + $sessionService->set("Common", SESSION_EDIT_LINK_TOKEN, $token); + $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); + $smarty->assign('token', $token->getValue()); + $smarty->assign('poll_id', $poll_id); + $message->includeTemplate = $smarty->fetch('part/form_remember_edit_link.tpl'); + $smarty->clearAssign('token'); + } } else { $message = new Message('success', __('studs', 'Update vote succeeded')); } @@ -179,7 +189,21 @@ if ($accessGranted) { $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, + __('Poll results', 'Edit the line:').' '.$name, + 'glyphicon-pencil'); + if ($config['use_smtp']) { + $token = new Token(); + $sessionService->set("Common", SESSION_EDIT_LINK_TOKEN, $token); + $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); + $smarty->assign('token', $token->getValue()); + $smarty->assign('poll_id', $poll_id); + $message->includeTemplate = $smarty->fetch('part/form_remember_edit_link.tpl'); + $smarty->clearAssign('token'); + } } else { $message = new Message('success', __('studs', 'Adding the vote succeeded')); } diff --git a/tpl/mail/remember_edit_link.tpl b/tpl/mail/remember_edit_link.tpl index 478561b..105e71e 100644 --- a/tpl/mail/remember_edit_link.tpl +++ b/tpl/mail/remember_edit_link.tpl @@ -1,9 +1,5 @@ -

{__('FindPolls', 'Here are your polls')}

- \ No newline at end of file +

{$poll->title|html|string_format:__('EditLink', 'Edit link for poll "%s"')}

+

+ {__('EditLink', 'Here is the link for editing your vote:')} + {$poll->title|html} +

\ No newline at end of file diff --git a/tpl/part/form_remember_edit_link.tpl b/tpl/part/form_remember_edit_link.tpl new file mode 100644 index 0000000..6cf6183 --- /dev/null +++ b/tpl/part/form_remember_edit_link.tpl @@ -0,0 +1,57 @@ +
+ + +
+ + \ No newline at end of file diff --git a/tpl/studs.tpl b/tpl/studs.tpl index ce45625..41bd991 100644 --- a/tpl/studs.tpl +++ b/tpl/studs.tpl @@ -16,6 +16,7 @@
{if !empty($message)} {/if}
+ {if !$accessGranted && !$resultPubliclyVisible}