From a7f83c411f64eb0b565a2c5ee2788711dd5d96fd Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Mon, 13 Nov 2023 07:34:58 +0100 Subject: [PATCH] WIP --- .../login-directive/login-directive.html | 4 +- .../login-directive/login-directive.js | 44 ++++++++++--------- dist/appCommon-v10.0.2.js | 34 +++++++------- dist/locales/en.json | 1 + locales/en.json | 1 + 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/avRegistration/login-directive/login-directive.html b/avRegistration/login-directive/login-directive.html index 941325a3..eb9b27a7 100644 --- a/avRegistration/login-directive/login-directive.html +++ b/avRegistration/login-directive/login-directive.html @@ -77,8 +77,8 @@ class="error text-danger" role="alert" ng-if="error" - ng-bind-html="error" - > + ng-i18next + >[html:i18next]({{errorData}}){{error}}
diff --git a/avRegistration/login-directive/login-directive.js b/avRegistration/login-directive/login-directive.js index a1e81d15..58516572 100644 --- a/avRegistration/login-directive/login-directive.js +++ b/avRegistration/login-directive/login-directive.js @@ -42,6 +42,7 @@ angular.module('avRegistration') scope.isOpenId = attrs.isOpenId; scope.otlSecret = attrs.otlSecret; scope.error = null; + scope.errorData = null; scope.current_alt_auth_method_id = undefined; scope.alternative_auth_methods = null; @@ -68,15 +69,16 @@ angular.module('avRegistration') // validate csrf token format and data return angular.fromJson($cookies.get(OIDC_ERROR_COOKIE)); } + scope.oidcError = parseOidcErrorCookie(); if (scope.oidcError) { scope.selectedAltMethod = scope.oidcError.altAuthMethodId; - scope.error = $i18next( - 'avRegistration.loginError.openid-connect.' + scope.oidcError.errorCodename, - { - support: '' + ConfigService.contact.email + "" - } + /* jshint ignore:start */ + setError( + scope.oidcError.errorCodename, + 'avRegistration.loginError.openid-connect.' + scope.oidcError.errorCodename ); + /* jshint ignore:end */ } // simply redirect to login @@ -248,6 +250,9 @@ angular.module('avRegistration') function setError(errorCodename, error) { scope.error = error; + scope.errorData = angular.toJson({ + support: '' + ConfigService.contact.email + "" + }); if (scope.isOpenId) { setOIDCErrorCookie(errorCodename); redirectToLogin(); @@ -488,7 +493,7 @@ angular.module('avRegistration') } ); scope.currentFormStep = 1; - scope.error = null; + setError(null, null); $timeout(scope.sendingDataTimeout, 3000); } @@ -504,7 +509,10 @@ angular.module('avRegistration') onAuthCodeSent, function onError(response) { $timeout(scope.sendingDataTimeout, 3000); - scope.error = $i18next('avRegistration.errorSendingAuthCode'); + setError( + null, + 'avRegistration.errorSendingAuthCode' + ); } ); }; @@ -659,7 +667,7 @@ angular.module('avRegistration') } scope.sendingData = true; - scope.error = null; + setError(null, null); var sessionStartedAtMs = Date.now(); Authmethod @@ -749,20 +757,14 @@ angular.module('avRegistration') } else { setError( "unrecognizedServerResponse", - $i18next( - 'avRegistration.loginError.' + scope.method + '.unrecognizedServerResponse', - {support: '' + ConfigService.contact.email + ""} - ) + 'avRegistration.loginError.' + scope.method + '.unrecognizedServerResponse' ); } } else { scope.sendingData = false; setError( "invalidServerResponse", - $i18next( - 'avRegistration.loginError.' + scope.method + '.invalidServerResponse', - {support: '' + ConfigService.contact.email + ""} - ) + 'avRegistration.loginError.' + scope.method + '.invalidServerResponse' ); } }, @@ -772,10 +774,7 @@ angular.module('avRegistration') setError( codename, - $i18next( - 'avRegistration.loginError.' + scope.method + '.' + codename, - {support: '' + ConfigService.contact.email + ""} - ) + 'avRegistration.loginError.' + scope.method + '.' + codename ); } ); @@ -1071,7 +1070,10 @@ angular.module('avRegistration') // find provider if (!provider) { - scope.error = $i18next('avRegistration.openidError'); + setError( + 'providerNotFound', + 'avRegistration.loginError.openid-connect.providerNotFound' + ); return; } diff --git a/dist/appCommon-v10.0.2.js b/dist/appCommon-v10.0.2.js index 2135f235..737aa713 100644 --- a/dist/appCommon-v10.0.2.js +++ b/dist/appCommon-v10.0.2.js @@ -452,8 +452,8 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist link: function(scope, element, attrs) { scope.isCensusQuery = attrs.isCensusQuery, scope.withCode = attrs.withCode, scope.username = attrs.username, scope.isOtl = attrs.isOtl, scope.isOpenId = attrs.isOpenId, scope.otlSecret = attrs.otlSecret, - scope.error = null, scope.current_alt_auth_method_id = void 0, scope.alternative_auth_methods = null, - scope.csrf = null, attrs.withAltMethod && attrs.selectedAltMethod ? scope.selectedAltMethod = attrs.selectedAltMethod : scope.selectedAltMethod = null, + scope.error = null, scope.errorData = null, scope.current_alt_auth_method_id = void 0, + scope.alternative_auth_methods = null, scope.csrf = null, attrs.withAltMethod && attrs.selectedAltMethod ? scope.selectedAltMethod = attrs.selectedAltMethod : scope.selectedAltMethod = null, scope.hide_default_login_lookup_field = !1; var adminId = ConfigService.freeAuthId + "", autheventid = null; function simpleRedirectToLogin() { @@ -499,12 +499,13 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist }), options); } function setError(errorCodename, error) { - scope.error = error, scope.isOpenId && (setOIDCErrorCookie(errorCodename), redirectToLogin()); + scope.error = error, scope.errorData = angular.toJson({ + support: '' + ConfigService.contact.email + "" + }), scope.isOpenId && (setOIDCErrorCookie(errorCodename), redirectToLogin()); } if (scope.oidcError = $cookies.get("OIDC_ERROR_COOKIE") ? angular.fromJson($cookies.get("OIDC_ERROR_COOKIE")) : null, - scope.oidcError && (scope.selectedAltMethod = scope.oidcError.altAuthMethodId, scope.error = $i18next("avRegistration.loginError.openid-connect." + scope.oidcError.errorCodename, { - support: '' + ConfigService.contact.email + "" - })), scope.isOpenId) { + scope.oidcError && (scope.selectedAltMethod = scope.oidcError.altAuthMethodId, setError(scope.oidcError.errorCodename, "avRegistration.loginError.openid-connect." + scope.oidcError.errorCodename)), + scope.isOpenId) { if (!function() { if (!$cookies.get("OIDC_CSRF")) return setOIDCErrorCookie("unexpectedOIDCRedirect"), void redirectToLogin(); @@ -541,14 +542,14 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist field && (field.value = ""), scope.sendingData = !0, scope.skipSendAuthCode) return onAuthCodeSent(), void (scope.skipSendAuthCode = !1); Authmethod.resendAuthCode(data, autheventid).then(onAuthCodeSent, function(response) { - $timeout(scope.sendingDataTimeout, 3e3), scope.error = $i18next("avRegistration.errorSendingAuthCode"); + $timeout(scope.sendingDataTimeout, 3e3), setError(null, "avRegistration.errorSendingAuthCode"); }); } } function onAuthCodeSent(response) { _.each(scope.login_fields, function(element) { void 0 !== element.steps && -1 === element.steps.indexOf(0) || (element.disabled = !0); - }), scope.currentFormStep = 1, scope.error = null, $timeout(scope.sendingDataTimeout, 3e3); + }), scope.currentFormStep = 1, setError(null, null), $timeout(scope.sendingDataTimeout, 3e3); } }, scope.sendingDataTimeout = function() { scope.sendingData = !1; @@ -604,7 +605,7 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist "smart-link" !== scope.method || scope.withCode || (data["auth-token"] = $location.search()["auth-token"]); } scope.current_alt_auth_method_id && (data.alt_auth_method_id = scope.current_alt_auth_method_id), - scope.sendingData = !0, scope.error = null; + scope.sendingData = !0, setError(null, null); var sessionStartedAtMs = Date.now(); Authmethod.login(data, autheventid).then(function(tokens) { var postfix, options; @@ -638,17 +639,12 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist sessionStartedAtMs: sessionStartedAtMs }; }).value(), $window.sessionStorage.setItem("vote_permission_tokens", JSON.stringify(tokens)), - $window.location.href = "/booth/" + autheventid + "/vote") : setError("unrecognizedServerResponse", $i18next("avRegistration.loginError." + scope.method + ".unrecognizedServerResponse", { - support: '' + ConfigService.contact.email + "" - }))) : (scope.sendingData = !1, setError("invalidServerResponse", $i18next("avRegistration.loginError." + scope.method + ".invalidServerResponse", { - support: '' + ConfigService.contact.email + "" - }))); + $window.location.href = "/booth/" + autheventid + "/vote") : setError("unrecognizedServerResponse", "avRegistration.loginError." + scope.method + ".unrecognizedServerResponse")) : (scope.sendingData = !1, + setError("invalidServerResponse", "avRegistration.loginError." + scope.method + ".invalidServerResponse")); }, function(codename) { scope.sendingData = !1; codename = codename.data.error_codename; - setError(codename, $i18next("avRegistration.loginError." + scope.method + "." + codename, { - support: '' + ConfigService.contact.email + "" - })); + setError(codename, "avRegistration.loginError." + scope.method + "." + codename); }); } }, scope.getUriParam = function(paramName2) { @@ -726,7 +722,7 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist eventId: scope.eventId, providerId: provider.public_info.id }), options), authURI = provider.public_info.authorization_endpoint + "?response_type=id_token&client_id=" + encodeURIComponent(provider.public_info.client_id) + "&scope=" + encodeURIComponent(provider.public_info.scope) + "&redirect_uri=" + encodeURIComponent($window.location.origin + "/election/login-openid-connect-redirect") + "&state=" + randomState + "&nonce=" + authURI, - $window.location.href = authURI) : scope.error = $i18next("avRegistration.openidError"); + $window.location.href = authURI) : setError("providerNotFound", "avRegistration.loginError.openid-connect.providerNotFound"); }; }, templateUrl: "avRegistration/login-directive/login-directive.html" @@ -1786,7 +1782,7 @@ angular.module("avTest", []), angular.module("avTest").controller("UnitTestE2ECo $templateCache.put("avRegistration/fields/textarea-field-directive/textarea-field-directive.html", '

'), $templateCache.put("avRegistration/loading.html", '

'), $templateCache.put("avRegistration/login-controller/login-controller.html", ''), - $templateCache.put("avRegistration/login-directive/login-directive.html", ''), + $templateCache.put("avRegistration/login-directive/login-directive.html", ''), $templateCache.put("avRegistration/register-controller/register-controller.html", '
'), $templateCache.put("avRegistration/register-directive/register-directive.html", '

avRegistration.fillValidFormText
'), $templateCache.put("avRegistration/success.html", '

'), diff --git a/dist/locales/en.json b/dist/locales/en.json index a795eb65..f4ad1a6c 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -62,6 +62,7 @@ "INVALID_USER_CREDENTIALS": "Invalid User Credentials.There are multiple reasons why this can happen:
  • Your email or authentication code are invalid.
  • Some other authentication credentials are invalid.
  • You are not part of the census.

Please review your credentials and try again.

If you think this is an error, please contact support at __support__.

" }, "openid-connect": { + "providerNotFound": "There was an error during authentication: Provider not found.

Please try again later. If the problem persists, please contact support at __support__.

", "invalidCsrf": "There was an error during authentication: Invalid CSRF Token.

Please try again later. If the problem persists, please contact support at __support__.

", "unexpectedOIDCRedirect": "There was an error during authentication: Unexpected OpenID Redirect.

Please try again later. If the problem persists, please contact support at __support__.

", "unrecognizedServerResponse": "There was an error during authentication: Unrecognized Server Response.

Please try again later. If the problem persists, please contact support at __support__.

", diff --git a/locales/en.json b/locales/en.json index 5784f1bc..ac2eebd0 100644 --- a/locales/en.json +++ b/locales/en.json @@ -63,6 +63,7 @@ "INVALID_USER_CREDENTIALS": "Invalid User Credentials.There are multiple reasons why this can happen:
  • Your email or authentication code are invalid.
  • Some other authentication credentials are invalid.
  • You are not part of the census.

Please review your credentials and try again.

If you think this is an error, please contact support at __support__.

" }, "openid-connect": { + "providerNotFound": "There was an error during authentication: Provider not found.

Please try again later. If the problem persists, please contact support at __support__.

", "invalidCsrf": "There was an error during authentication: Invalid CSRF Token.

Please try again later. If the problem persists, please contact support at __support__.

", "unexpectedOIDCRedirect": "There was an error during authentication: Unexpected OpenID Redirect.

Please try again later. If the problem persists, please contact support at __support__.

", "unrecognizedServerResponse": "There was an error during authentication: Unrecognized Server Response.

Please try again later. If the problem persists, please contact support at __support__.

",