mirror of
https://github.com/moparisthebest/mail
synced 2025-02-16 15:10:10 -05:00
Refactor BOs and utils to services
This commit is contained in:
parent
ac09c7d91f
commit
38d908995a
@ -1,16 +1,19 @@
|
||||
/**
|
||||
* High level crypto api that invokes native crypto (if available) and
|
||||
* gracefully degrades to JS crypto (if unavailable)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ngModule = angular.module('woCrypto');
|
||||
ngModule.service('crypto', Crypto);
|
||||
module.exports = Crypto;
|
||||
|
||||
var aes = require('crypto-lib').aes,
|
||||
pbkdf2 = require('./pbkdf2'),
|
||||
config = require('../app-config').config,
|
||||
axe = require('axe-logger');
|
||||
|
||||
var Crypto = function() {};
|
||||
/**
|
||||
* High level crypto api that invokes native crypto (if available) and
|
||||
* gracefully degrades to JS crypto (if unavailable)
|
||||
*/
|
||||
function Crypto() {}
|
||||
|
||||
/**
|
||||
* Encrypt plaintext using AES-GCM.
|
||||
@ -115,6 +118,4 @@ function startWorker(options) {
|
||||
return;
|
||||
}
|
||||
options.callback(null, result);
|
||||
}
|
||||
|
||||
module.exports = Crypto;
|
||||
}
|
6
src/js/crypto/index.js
Normal file
6
src/js/crypto/index.js
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('woCrypto', []);
|
||||
|
||||
require('./pgp');
|
||||
require('./crypto');
|
@ -1,16 +1,19 @@
|
||||
/**
|
||||
* High level crypto api that handles all calls to OpenPGP.js
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ngModule = angular.module('woCrypto');
|
||||
ngModule.service('pgp', PGP);
|
||||
module.exports = PGP;
|
||||
|
||||
var util = openpgp.util,
|
||||
config = require('../app-config').config;
|
||||
|
||||
var PGP = function() {
|
||||
/**
|
||||
* High level crypto api that handles all calls to OpenPGP.js
|
||||
*/
|
||||
function PGP() {
|
||||
openpgp.config.prefer_hash_algorithm = openpgp.enums.hash.sha256;
|
||||
openpgp.initWorker(config.workerPath + '/openpgp.worker.min.js');
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a key pair for the user
|
||||
@ -426,6 +429,4 @@ function checkSignatureValidity(signatures) {
|
||||
|
||||
// everything is in order
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = PGP;
|
||||
}
|
@ -13,7 +13,7 @@ function Account() {
|
||||
* Lists all of the current accounts connected to the app
|
||||
* @return {Array<Object>} The account objects containing folder and message objects
|
||||
*/
|
||||
Account.prototype.all = function() {
|
||||
Account.prototype.list = function() {
|
||||
return this._emailDAOs.map(function(emailDao) {
|
||||
return emailDao._account;
|
||||
});
|
||||
|
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var ngModule = angular.module('woServices');
|
||||
ngModule.service('auth', Auth);
|
||||
module.exports = Auth;
|
||||
|
||||
var axe = require('axe-logger'),
|
||||
cfg = require('../app-config').config,
|
||||
str = require('../app-config').string;
|
||||
@ -21,11 +25,11 @@ var SMTP_DB_KEY = 'smtp';
|
||||
* auth.getCredentials(...); // called to gather all the information to connect to IMAP/SMTP,
|
||||
* username, password / oauth token, IMAP/SMTP server host names, ...
|
||||
*/
|
||||
var Auth = function(appConfigStore, oauth, pgp) {
|
||||
function Auth(appConfigStore, oauth, pgp) {
|
||||
this._appConfigStore = appConfigStore;
|
||||
this._oauth = oauth;
|
||||
this._pgp = pgp;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves credentials and IMAP/SMTP settings:
|
||||
@ -439,6 +443,4 @@ Auth.prototype.logout = function(callback) {
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Auth;
|
||||
};
|
@ -1,14 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var ngModule = angular.module('woServices');
|
||||
ngModule.service('deviceStorage', DeviceStorage);
|
||||
ngModule.factory('deviceStorage', ['lawnchairDAO', function(lawnchairDAO) {
|
||||
return new DeviceStorage(lawnchairDAO);
|
||||
}]);
|
||||
module.exports = DeviceStorage;
|
||||
|
||||
/**
|
||||
* High level storage api that handles all persistence on the device.
|
||||
*/
|
||||
function DeviceStorage(localDbDao) {
|
||||
this._localDbDao = localDbDao;
|
||||
function DeviceStorage(lawnchairDAO) {
|
||||
this._localDbDao = lawnchairDAO;
|
||||
}
|
||||
|
||||
DeviceStorage.prototype.init = function(emailAddress, callback) {
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
angular.module('woServices', []);
|
||||
|
||||
require('./newsletter'),
|
||||
require('./mail-config'),
|
||||
require('./newsletter');
|
||||
require('./mail-config');
|
||||
require('./account');
|
@ -4,12 +4,15 @@ var ngModule = angular.module('woServices');
|
||||
ngModule.service('invitation', Invitation);
|
||||
module.exports = Invitation;
|
||||
|
||||
var config = require('../app-config').config;
|
||||
|
||||
/**
|
||||
* The Invitation is a high level Data Access Object that access the invitation service REST endpoint.
|
||||
* @param {Object} restDao The REST Data Access Object abstraction
|
||||
*/
|
||||
function Invitation(restDao) {
|
||||
this._restDao = restDao;
|
||||
this._restDao.setBaseUri(config.cloudUrl);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1,7 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var ngModule = angular.module('woServices');
|
||||
ngModule.service('lawnchairDAO', LawnchairDAO);
|
||||
ngModule.factory('lawnchairDAO', function() {
|
||||
return new LawnchairDAO();
|
||||
});
|
||||
module.exports = LawnchairDAO;
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var OAuth = function(googleApi) {
|
||||
this._googleApi = googleApi;
|
||||
};
|
||||
var ngModule = angular.module('woServices');
|
||||
ngModule.service('oauth', OAuth);
|
||||
module.exports = OAuth;
|
||||
|
||||
function OAuth(restDao) {
|
||||
this._googleApi = restDao;
|
||||
this._googleApi.setBaseUri('https://www.googleapis.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if chrome.identity api is supported
|
||||
@ -94,6 +99,4 @@ OAuth.prototype.queryEmailAddress = function(token, callback) {
|
||||
|
||||
callback(null, info.email);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = OAuth;
|
||||
};
|
@ -4,8 +4,11 @@ var ngModule = angular.module('woServices');
|
||||
ngModule.service('privateKey', PrivateKey);
|
||||
module.exports = PrivateKey;
|
||||
|
||||
var config = require('../app-config').config;
|
||||
|
||||
function PrivateKey(restDao) {
|
||||
this._restDao = restDao;
|
||||
this._restDao.setBaseUri(config.privkeyServerUrl);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -4,8 +4,11 @@ var ngModule = angular.module('woServices');
|
||||
ngModule.service('publicKey', PublicKey);
|
||||
module.exports = PublicKey;
|
||||
|
||||
var config = require('../app-config').config;
|
||||
|
||||
function PublicKey(restDao) {
|
||||
this._restDao = restDao;
|
||||
this._restDao.setBaseUri(config.cloudUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,15 +6,15 @@ ngModule.factory('restDao', function() {
|
||||
});
|
||||
module.exports = RestDAO;
|
||||
|
||||
var config = require('../app-config').config;
|
||||
function RestDAO() {}
|
||||
|
||||
function RestDAO(baseUri) {
|
||||
if (baseUri) {
|
||||
this._baseUri = baseUri;
|
||||
} else {
|
||||
this._baseUri = config.cloudUrl;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the REST DAO's base url
|
||||
* @param {String} baseUri The base url e.g. https://api.example.com
|
||||
*/
|
||||
RestDAO.prototype.setBaseUri = function(baseUri) {
|
||||
this._baseUri = baseUri;
|
||||
};
|
||||
|
||||
/**
|
||||
* GET (read) request
|
||||
|
Loading…
Reference in New Issue
Block a user