From 1da17630850085fd55dd76f816a2436f8bb7d6c3 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Mon, 13 Mar 2017 12:01:36 +0100 Subject: [PATCH] - bad invitation content parse - Fix #385 --- app/config.json | 15 +++++------ www/js/controllers/wot-controllers.js | 5 ++++ www/plugins/es/i18n/locale-en-GB.json | 6 ++--- www/plugins/es/i18n/locale-en.json | 6 ++--- www/plugins/es/i18n/locale-fr-FR.json | 3 ++- .../js/controllers/invitation-controllers.js | 2 +- www/plugins/es/js/entities/invitation.js | 26 ++++++++++++++++--- .../templates/invitation/list_invitation.html | 1 + 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/config.json b/app/config.json index 792fe7ec4..f4c2ea9e1 100644 --- a/app/config.json +++ b/app/config.json @@ -37,7 +37,7 @@ } }, - "g1": { + "gtest": { "cacheTimeMs": 60000, "fallbackLanguage": "en", "rememberMe": false, @@ -47,17 +47,15 @@ "timeWarningExpire": 7776000, "useLocalStorage": true, "useRelative": false, - "initPhase": true, - "expertMode": false, + "expertMode": true, "decimalCount": 4, - "httpsMode": false, "helptip": { "enable": true, "installDocUrl": "https://github.com/duniter/duniter/blob/master/doc/install-a-node.md" }, "node": { - "host": "g1.duniter.org", - "port": 443 + "host": "gtest.duniter.org", + "port": 10900 }, "plugins":{ "es": { @@ -86,7 +84,6 @@ "timeWarningExpire": 7776000, "useLocalStorage": true, "useRelative": true, - "initPhase": false, "expertMode": true, "helptip": { "enable": false, @@ -96,8 +93,8 @@ } }, "node": { - "host": "gtest.duniter.fr", - "port": "10900" + "host": "gtest.duniter.org", + "port": 10900 }, "plugins":{ "es": { diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index bfc74d37a..056119c24 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -577,6 +577,11 @@ function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ return; } + if (!csConfig.initPhase && !$scope.formData.hasSelf) { + UIUtils.alert.error('ERROR.IDENTITY_TO_CERTIFY_HAS_NO_SELF'); + return; + } + // Check identity not expired if ($scope.formData.requirements.expired) { UIUtils.alert.error('ERROR.IDENTITY_EXPIRED'); diff --git a/www/plugins/es/i18n/locale-en-GB.json b/www/plugins/es/i18n/locale-en-GB.json index a603cb1dc..41d5b0817 100644 --- a/www/plugins/es/i18n/locale-en-GB.json +++ b/www/plugins/es/i18n/locale-en-GB.json @@ -54,9 +54,6 @@ "SUGGEST_CERTIFICATIONS": "Etes-vous sûr de vouloir <b>envoyer ces suggestions de certification</b> ?", "ASK_CERTIFICATION": "Etes-vous sûr de vouloir <b>envoyer une demande de certification</b> ?", "ASK_CERTIFICATIONS": "Etes-vous sûr de vouloir <b>envoyer une demande de certification</b> à ces personnes ?" - }, - "ERROR": { - "SEND_INVITATION_CERTIFICATION_FAILED": "Echec de l'envoi de la demande de certification" } }, "INVITATION": { @@ -96,7 +93,8 @@ "LOAD_INVITATIONS_FAILED": "Error while loading invitations", "REMOVE_INVITATION_FAILED": "Error while deleting the invitation", "REMOVE_ALL_INVITATIONS_FAILED": "Error while deleting invitations", - "SUGGEST_CERTIFICATIONS_FAILED": "Error while sending invitation" + "SUGGEST_CERTIFICATIONS_FAILED": "Error while sending invitation", + "BAD_INVITATION_FORMAT": "<span class=\"assertive\"><i class=\"ion-close-circled\"></i> Invitation unreadable (format unknown)</span> - sent by <a href=\"#/app/wot/{{pubkey}}/{{::uid}}\">{{::name||uid||pubkey}}</a>" } }, "COMMENTS": { diff --git a/www/plugins/es/i18n/locale-en.json b/www/plugins/es/i18n/locale-en.json index a603cb1dc..41d5b0817 100644 --- a/www/plugins/es/i18n/locale-en.json +++ b/www/plugins/es/i18n/locale-en.json @@ -54,9 +54,6 @@ "SUGGEST_CERTIFICATIONS": "Etes-vous sûr de vouloir <b>envoyer ces suggestions de certification</b> ?", "ASK_CERTIFICATION": "Etes-vous sûr de vouloir <b>envoyer une demande de certification</b> ?", "ASK_CERTIFICATIONS": "Etes-vous sûr de vouloir <b>envoyer une demande de certification</b> à ces personnes ?" - }, - "ERROR": { - "SEND_INVITATION_CERTIFICATION_FAILED": "Echec de l'envoi de la demande de certification" } }, "INVITATION": { @@ -96,7 +93,8 @@ "LOAD_INVITATIONS_FAILED": "Error while loading invitations", "REMOVE_INVITATION_FAILED": "Error while deleting the invitation", "REMOVE_ALL_INVITATIONS_FAILED": "Error while deleting invitations", - "SUGGEST_CERTIFICATIONS_FAILED": "Error while sending invitation" + "SUGGEST_CERTIFICATIONS_FAILED": "Error while sending invitation", + "BAD_INVITATION_FORMAT": "<span class=\"assertive\"><i class=\"ion-close-circled\"></i> Invitation unreadable (format unknown)</span> - sent by <a href=\"#/app/wot/{{pubkey}}/{{::uid}}\">{{::name||uid||pubkey}}</a>" } }, "COMMENTS": { diff --git a/www/plugins/es/i18n/locale-fr-FR.json b/www/plugins/es/i18n/locale-fr-FR.json index 2f838a350..814eee5b2 100644 --- a/www/plugins/es/i18n/locale-fr-FR.json +++ b/www/plugins/es/i18n/locale-fr-FR.json @@ -93,7 +93,8 @@ "LOAD_INVITATIONS_FAILED": "Echec du chargement des invitations", "REMOVE_INVITATION_FAILED": "Erreur lors de la suppression de l'invitation", "REMOVE_ALL_INVITATIONS_FAILED": "Erreur lors de la suppression des invitations", - "SEND_INVITATION_FAILED": "Erreur lors de l'envoi de l'invitation" + "SEND_INVITATION_FAILED": "Erreur lors de l'envoi de l'invitation", + "BAD_INVITATION_FORMAT": "<span class=\"assertive\"><i class=\"ion-close-circled\"></i> Invitation illisible (format inconnu)</span> - envoyée par <a href=\"#/app/wot/{{pubkey}}/{{::uid}}\">{{::name||uid}}</a>" } }, "COMMENTS": { diff --git a/www/plugins/es/js/controllers/invitation-controllers.js b/www/plugins/es/js/controllers/invitation-controllers.js index 87d632d91..f51244728 100644 --- a/www/plugins/es/js/controllers/invitation-controllers.js +++ b/www/plugins/es/js/controllers/invitation-controllers.js @@ -174,7 +174,7 @@ function InvitationsController($scope, $q, $ionicPopover, $state, $timeout, UIUt }; $scope.accept = function(invitation) { - $scope.hideActionsPopover(); // useful in PopoverInvitationController + $scope.hideActionsPopover(); // need when PopoverInvitationController if (invitation.state) { $state.go(invitation.state, invitation.stateParams || {}); diff --git a/www/plugins/es/js/entities/invitation.js b/www/plugins/es/js/entities/invitation.js index f333d7373..9cad93a0e 100644 --- a/www/plugins/es/js/entities/invitation.js +++ b/www/plugins/es/js/entities/invitation.js @@ -18,11 +18,29 @@ function Invitation(json) { that.okText= 'WOT.BTN_CERTIFY'; // read the identity to certify - var parts = json.content.split('-'); - if (parts.length != 2) { - throw 'Invalid invitation content. format should be [uid-pubkey]'; + if (!json.content || json.content.indexOf('-') == -1) { + console.error('[invitation] Empty content for invitation [{0}]'.format(that.id)); + that.message = 'INVITATION.ERROR.BAD_INVITATION_FORMAT'; + that.pubkey = json.issuer; + return; + } + + var separatorIndex = json.content.lastIndexOf('-'); + if (separatorIndex == -1) { + console.error('[invitation] Bad content format for invitation [{0}]: {1}'.format(that.id, json.content)); + that.message = 'INVITATION.ERROR.BAD_INVITATION_FORMAT'; + that.pubkey = json.issuer; + return; } - var identity = { uid: parts[0], pubkey: parts[1] }; + + that.message = 'INVITATION.ERROR.BAD_INVITATION_FORMAT'; + that.pubkey = json.issuer; + return; + + var identity = { + uid: json.content.substr(0, separatorIndex), + pubkey: json.content.substr(separatorIndex+1) + }; // Prepare the state action that.state = 'app.wot_identity'; diff --git a/www/plugins/es/templates/invitation/list_invitation.html b/www/plugins/es/templates/invitation/list_invitation.html index 004e9d0ae..098d27a81 100644 --- a/www/plugins/es/templates/invitation/list_invitation.html +++ b/www/plugins/es/templates/invitation/list_invitation.html @@ -20,6 +20,7 @@ <div class="block text-right"> <button class="button button-positive button-small button-small-padding" ng-click="accept(invitation)" + ng-if="::invitation.state" translate>{{::(invitation.okText||'COMMON.BTN_SHOW') |translate}}</button> <button class="button button-stable button-small button-small-padding" ng-click="delete($index)" -- GitLab