Skip to content

Commit

Permalink
🐞 redirect at the end of voting if public page is disabled (#398) (#399)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#262
  • Loading branch information
edulix committed Oct 9, 2023
1 parent e7d7d53 commit 19d7f75
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 12 deletions.
80 changes: 70 additions & 10 deletions avBooth/booth-directive/booth-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,15 @@ angular.module('avBooth')
if (InsideIframeService()) {
return;
} else {
redirectToLogin(/* isSuccess */ false);
showError(
"avBooth.errorLoadingVoterCredentials",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
},
"400"
);
return;
}
}
scope.credentials = [];
Expand All @@ -669,31 +677,55 @@ angular.module('avBooth')
}
);
} catch (error) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}

// credentials for current election should have been found
if (!currentElectionCredentials)
{
if (scope.election) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
}
return;
}

// token should be valid
var hmac = HmacService.checkKhmac(currentElectionCredentials.token);
if (!hmac) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}

// verify message, which should be of the format
// "userid:vote:AuthEvent:1110:134234111"
var splitMessage = hmac.message.split(':');
if (splitMessage.length !== 5) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}
var voterId = splitMessage[0];
Expand All @@ -706,7 +738,13 @@ angular.module('avBooth')
action !== 'vote' ||
objectType !== 'AuthEvent'
) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}

Expand Down Expand Up @@ -787,7 +825,6 @@ angular.module('avBooth')

}
}
autoredirectToLoginAfterTimeout();

function simpleGetElection(electionId) {
if (!electionId) {
Expand Down Expand Up @@ -839,6 +876,9 @@ angular.module('avBooth')
}

function retrieveElectionConfig(electionId) {
if (scope.state === stateEnum.errorScreen) {
return;
}
if (electionId) {
scope.electionId = electionId;
}
Expand Down Expand Up @@ -1024,7 +1064,13 @@ angular.module('avBooth')

if (scope.isVirtual) {
if (hasAuthapiError) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}
sequentElectionsRetrieved = true;
Expand Down Expand Up @@ -1111,7 +1157,13 @@ angular.module('avBooth')
}
);
} catch (error) {
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
}
}

Expand All @@ -1127,7 +1179,13 @@ angular.module('avBooth')
var khmac = HmacService.checkKhmac(khmacStr);
if (!khmac) {
scope.authorizationReceiverErrorHandler();
showError("avBooth.errorLoadingElection");
showError(
"avBooth.errorLoadingElection",
{
"backButtonUrl": ConfigService.defaultRoute,
"hideErrorIdentifier": true
}
);
return;
}
scope.authorizationHeader = khmacStr;
Expand Down Expand Up @@ -1230,6 +1288,8 @@ angular.module('avBooth')
// allow receival of khmac token by parent window
$window.addEventListener('message', avPostAuthorization, false);

autoredirectToLoginAfterTimeout();

// retrieve election config
retrieveElectionConfig();
}
Expand Down
6 changes: 5 additions & 1 deletion avBooth/error-screen-directive/error-screen-directive.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ <h1>{{errorCode}}</h1>

<div class="block-wrapper">
<h3 class="error-code-text" ng-i18next>{{errorCodeTranslation}}</h3>
<p ng-i18next="[html:i18next]({errorId: errorId})avBooth.errorScreen.identifier"></p>
<p
ng-if="showErrorIdentifier"
ng-i18next="[html:i18next]({errorId: errorId})avBooth.errorScreen.identifier"
></p>
<p class="error-description" ng-i18next>
{{stateData.error}}
</p>
<p ng-i18next="[html:i18next]({email: config.contact.email})avBooth.errorScreen.help"></p>
<button
ng-if="showBackButton"
ng-click="goBack()"
class="btn btn-lg btn-success-action" ng-i18next>
avBooth.errorScreen.backButton
Expand Down
27 changes: 26 additions & 1 deletion avBooth/error-screen-directive/error-screen-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,36 @@ angular.module('avBooth')
scope.errorId = "generic";
}

// Stop warning the user about reloading/leaving the page
// as no vote is in the process
$window.onbeforeunload = null;
scope.errorCode = scope.stateData.errorCode || 500;
scope.errorCodeTranslation = "avBooth.errorScreen." + scope.errorCode;
scope.showBackButton = true;

if (
scope.stateData.errorData &&
scope.stateData.errorData.showBackButton === false
) {
scope.showBackButton = false;
}

scope.showErrorIdentifier = true;
if (
scope.stateData.errorData &&
scope.stateData.errorData.showErrorIdentifier === false
) {
scope.showErrorIdentifier = false;
}

scope.goBack = function () {
scope.setState(scope.stateEnum.startScreen, {});
if (
scope.stateData.errorData &&
angular.isString(scope.stateData.errorData.backButtonUrl)
) {
$window.location.href = scope.stateData.errorData.backButtonUrl;
}
scope.setState(scope.stateEnum.startScreen, {});
};
}
return {
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"errorTitle": "Oops. Something unexpected happened",
"errorHtml": "<p>The following problem arised (identifier __errorId__): </p><p>__error__</p><p>If you think that you need to contact us, you can do so sending an email to <a href=\"mailto:__email__\" target=\"_blank\">__email__</a>.</p>",
"errorLoadingImages": "Error on voting booth. Images not loaded.",
"errorLoadingVoterCredentials": "Error loading voter credentials. This could be happening for multiple reasons: this link might be invalid, you might have typed it incorrectly or the link might have been incorrectly crafted. Please, try to produce the link again.",
"errorLoadingElection": "Error loading the election. This could be happenning for multiple reasons: the link might be invalid, you might have typed it incorrectly or the link might have been incorrectly crafted. Please, try to produce the link again. Finally, the server might be temporarily unavailable. If that's the case, try again later and if the issue persists please contact us.",
"errorLoadingElectionPubKeys": "Error loading the election public keys. This could be happenning for multiple reasons: the link might be invalid, you might have typed it incorrectly or the link might have been incorrectly crafted. Please, try to produce the link again. Finally, the server might be temporarily unavailable. If that's the case, try again later and if the issue persists please contact us.",
"errorSendingBallot": "Error sending the ballot. It was not correctly cast. Please, try again in another and more updated web browser, and if the problem persists try to contact us. Sorry for the inconvenience.",
Expand Down
1 change: 1 addition & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"errorTitle": "Oops. Ocurrió algo inesperado",
"errorHtml": "<p>Ocurrió el siguiente problema (identificador __errorId__): </p><p>__error__</p><p>En caso de que crea que debes contactar con nosotros, puede hacerlo enviándonos un email a <a href=\"mailto:__email__\" target=\"_blank\">__email__</a>.</p>",
"errorLoadingImages": "Error en cabina de voto. Imágenes no cargadas.",
"errorLoadingVoterCredentials": "Error al cargar las credenciales del votante. Esto podría estar ocurriendo por varias razones: este enlace podría ser inválido, es posible que lo haya escrito incorrectamente o el enlace podría haber sido creado incorrectamente. Por favor, intente generar el enlace nuevamente.",
"errorLoadingElection": "Error cargando la votación. Esto puede ocurrir por múltiples motivos: puede que este enlace sea incorrecto, puede que lo haya introducido o se haya generado mal. Para ello comprueba a generarlo de nuevo. Finalmente, puede ocurrir que el servidor no esté disponible temporalmente. Si se trata de este caso, prueba de nuevo más tarde y si el problema persiste ponte en contacto con nosotros.",
"errorLoadingElectionPubKeys": "Error cargando las claves públicas de la votación. Esto puede ocurrir por múltiples motivos: puede que este enlace sea incorrecto, puede que lo haya introducido o se haya generado mal. Para ello compruebe a generarlo de nuevo. Finalmente, puede ocurrir que el servidor no esté disponible temporalmente. Si se trata de este caso, pruebe de nuevo más tarde y si el problema persiste póngase en contacto con nosotros.",
"errorSendingBallot": "Error enviando el voto, por lo que no ha podido ser registrado correctamente. Por favor, inténtelo de nuevo en otro navegador web diferente y más actualizado, y si el problema persiste póngase en contacto con nosotros. Disculpe las molestias.",
Expand Down

0 comments on commit 19d7f75

Please sign in to comment.