From 71fbd2000548ad3a711a914a2376b522aadf9577 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Wed, 9 May 2018 10:54:29 +0200
Subject: [PATCH] [fix] Login using file + drag&drop failed - Fix #696

---
 www/js/controllers/login-controllers.js | 5 +++--
 www/js/services/crypto-services.js      | 8 ++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js
index 8487c833..59b5b367 100644
--- a/www/js/controllers/login-controllers.js
+++ b/www/js/controllers/login-controllers.js
@@ -337,9 +337,10 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
 
     $scope.formData.file = {
       name: file.fileData.name,
-      size: file.fileData.size
+      size: file.fileData.size,
+      content: file.fileContent
     };
-    return CryptoUtils.parseKeyFileContent(file.fileContent, false/*withSecret*/)
+    return CryptoUtils.readKeyFile($scope.formData.file, false/*withSecret*/)
       .then(function(keypair) {
         if (!keypair || !keypair.signPk) {
           $scope.formData.file.valid = false;
diff --git a/www/js/services/crypto-services.js b/www/js/services/crypto-services.js
index 19833ed0..3c025237 100644
--- a/www/js/services/crypto-services.js
+++ b/www/js/services/crypto-services.js
@@ -141,6 +141,11 @@ angular.module('cesium.crypto.services', ['cesium.utils.services'])
 
     CryptoAbstractService.prototype.readKeyFile = function(file, withSecret) {
       var that = this;
+
+      if (file && file.content) {
+        return  that.parseKeyFileContent(file.content, withSecret);
+      }
+
       return $q(function(resolve, reject) {
         if (!file) {
           return reject('Argument [file] is missing');
@@ -149,8 +154,7 @@ angular.module('cesium.crypto.services', ['cesium.utils.services'])
         console.debug('[crypto] [keypair] reading file: ', file);
         var reader = new FileReader();
         reader.onload = function (event) {
-          var res = that.parseKeyFileContent(event.target.result, withSecret);
-          res
+          that.parseKeyFileContent(event.target.result, withSecret)
             .then(function (res) {
               resolve(res);
             })
-- 
GitLab