mirror of
https://github.com/moparisthebest/mail
synced 2024-08-13 16:43:47 -04:00
6adc9da8c1
* Add ng-animate module in libs * Move error dialog init to app.run * Include error dialog template only once in index.html * Fix race condition between ng-repeat, ng-class using ng-animate
104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
define(function(require) {
|
|
'use strict';
|
|
|
|
var angular = require('angular'),
|
|
appController = require('js/app-controller');
|
|
|
|
var LoginExistingCtrl = function($scope, $location) {
|
|
var emailDao = appController._emailDao,
|
|
pgp = appController._crypto;
|
|
|
|
$scope.incorrect = false;
|
|
|
|
$scope.confirmPassphrase = function() {
|
|
$scope.incorrect = false;
|
|
unlockCrypto();
|
|
};
|
|
|
|
function unlockCrypto() {
|
|
var userId = emailDao._account.emailAddress;
|
|
// check if user already has a public key on the key server
|
|
emailDao._keychain.getUserKeyPair(userId, function(err, keypair) {
|
|
if (err) {
|
|
$scope.onError(err);
|
|
return;
|
|
}
|
|
|
|
keypair = keypair || {};
|
|
|
|
// set parsed private key
|
|
keypair.privateKey = {
|
|
_id: pgp.getKeyId($scope.key.privateKeyArmored),
|
|
userId: userId,
|
|
encryptedKey: $scope.key.privateKeyArmored
|
|
};
|
|
|
|
if (!keypair.publicKey) {
|
|
// there is no public key on the key server yet... use parsed
|
|
keypair.publicKey = {
|
|
_id: pgp.getKeyId($scope.key.publicKeyArmored),
|
|
userId: userId,
|
|
publicKey: $scope.key.publicKeyArmored
|
|
};
|
|
}
|
|
|
|
// import and validate keypair
|
|
emailDao.unlock({
|
|
keypair: keypair,
|
|
passphrase: $scope.passphrase
|
|
}, function(err) {
|
|
if (err) {
|
|
$scope.incorrect = true;
|
|
$scope.onError(err);
|
|
return;
|
|
}
|
|
|
|
emailDao._keychain.putUserKeyPair(keypair, onUnlock);
|
|
});
|
|
});
|
|
}
|
|
|
|
function onUnlock(err) {
|
|
if (err) {
|
|
$scope.onError(err);
|
|
return;
|
|
}
|
|
|
|
$location.path('/desktop');
|
|
$scope.$apply();
|
|
}
|
|
};
|
|
|
|
var ngModule = angular.module('login-new-device', []);
|
|
ngModule.directive('fileReader', function() {
|
|
return function(scope, elm) {
|
|
elm.bind('change', function(e) {
|
|
var files = e.target.files,
|
|
reader = new FileReader();
|
|
|
|
if (files.length === 0) {
|
|
return;
|
|
}
|
|
|
|
reader.onload = function(e) {
|
|
var rawKeys = e.target.result,
|
|
index = rawKeys.indexOf('-----BEGIN PGP PRIVATE KEY BLOCK-----');
|
|
|
|
if (index === -1) {
|
|
console.error('Erroneous key file format!');
|
|
return;
|
|
}
|
|
|
|
scope.key = {
|
|
publicKeyArmored: rawKeys.substring(0, index),
|
|
privateKeyArmored: rawKeys.substring(index, rawKeys.length)
|
|
};
|
|
scope.$apply();
|
|
};
|
|
reader.readAsText(files[0]);
|
|
});
|
|
};
|
|
});
|
|
|
|
return LoginExistingCtrl;
|
|
}); |