Unified mongo and email style
This commit is contained in:
@@ -25,21 +25,15 @@ const MongoClient = require('mongodb').MongoClient;
|
||||
class Mongo {
|
||||
|
||||
/**
|
||||
* Create an instance of the MongoDB client.
|
||||
* Initializes the database client by connecting to the MongoDB.
|
||||
* @param {String} uri The mongodb uri
|
||||
* @param {String} user The databse user
|
||||
* @param {String} pass The database user's password
|
||||
*/
|
||||
constructor(options) {
|
||||
this._uri = 'mongodb://' + options.user + ':' + options.pass + '@' + options.uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the database client by connecting to the MongoDB.
|
||||
* @yield {undefined}
|
||||
*/
|
||||
*connect() {
|
||||
this._db = yield MongoClient.connect(this._uri);
|
||||
*init(options) {
|
||||
let uri = 'mongodb://' + options.user + ':' + options.pass + '@' + options.uri;
|
||||
this._db = yield MongoClient.connect(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,21 +19,14 @@
|
||||
|
||||
const log = require('npmlog');
|
||||
const util = require('../service/util');
|
||||
const nodemailer = require('nodemailer');
|
||||
const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt;
|
||||
|
||||
/**
|
||||
* A simple wrapper around Nodemailer to send verification emails
|
||||
*/
|
||||
class Email {
|
||||
|
||||
/**
|
||||
* Create an instance of the email object.
|
||||
* @param {Object} mailer An instance of nodemailer
|
||||
*/
|
||||
constructor(mailer, openpgpEncrypt) {
|
||||
this._mailer = mailer;
|
||||
this._openpgpEncrypt = openpgpEncrypt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the reusable nodemailer SMTP transport.
|
||||
* @param {string} host SMTP server's hostname: 'smtp.gmail.com'
|
||||
@@ -45,7 +38,7 @@ class Email {
|
||||
* @param {boolean} pgp (optional) if outgoing emails are encrypted to the user's public key.
|
||||
*/
|
||||
init(options) {
|
||||
this._transport = this._mailer.createTransport({
|
||||
this._transport = nodemailer.createTransport({
|
||||
host: options.host,
|
||||
port: options.port || 465,
|
||||
auth: options.auth,
|
||||
@@ -53,7 +46,7 @@ class Email {
|
||||
requireTLS: (options.starttls !== undefined) ? util.isTrue(options.starttls) : true,
|
||||
});
|
||||
if (util.isTrue(options.pgp)) {
|
||||
this._transport.use('stream', this._openpgpEncrypt());
|
||||
this._transport.use('stream', openpgpEncrypt());
|
||||
}
|
||||
this._sender = options.sender;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user