add email validation
This commit is contained in:
parent
910a1c8ddc
commit
a643819b46
|
@ -40,7 +40,7 @@ var config = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// To use email notifications uncomment this:
|
// To use email notifications uncomment this:
|
||||||
email: {
|
emailOpts: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 25,
|
port: 25,
|
||||||
ignoreTLS: true,
|
ignoreTLS: true,
|
||||||
|
|
|
@ -33,13 +33,13 @@ var EMAIL_TYPES = {
|
||||||
function EmailService(opts) {
|
function EmailService(opts) {
|
||||||
$.checkArgument(opts);
|
$.checkArgument(opts);
|
||||||
|
|
||||||
opts.email = opts.email || {};
|
opts.emailOpts = opts.emailOpts || {};
|
||||||
|
|
||||||
this.storage = opts.storage;
|
this.storage = opts.storage;
|
||||||
this.lock = opts.lock;
|
this.lock = opts.lock;
|
||||||
this.mailer = opts.mailer || nodemailer.createTransport(opts.email);
|
this.mailer = opts.mailer || nodemailer.createTransport(opts.emailOpts);
|
||||||
this.subjectPrefix = opts.email.subjectPrefix || '[Wallet service]';
|
this.subjectPrefix = opts.emailOpts.subjectPrefix || '[Wallet service]';
|
||||||
this.from = opts.email.from;
|
this.from = opts.emailOpts.from;
|
||||||
|
|
||||||
$.checkState(this.mailer);
|
$.checkState(this.mailer);
|
||||||
$.checkState(this.from);
|
$.checkState(this.from);
|
||||||
|
|
|
@ -87,7 +87,7 @@ WalletService.initialize = function(opts, cb) {
|
||||||
lock: lock,
|
lock: lock,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
mailer: opts.mailer,
|
mailer: opts.mailer,
|
||||||
email: opts.email,
|
emailOpts: opts.emailOpts,
|
||||||
});
|
});
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
@ -448,6 +448,12 @@ WalletService.prototype.savePreferences = function(opts, cb) {
|
||||||
|
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
if (opts.email) {
|
||||||
|
if (opts.email.length > 254 || opts.email.indexOf('@') == -1) {
|
||||||
|
return cb(new ClientError('Invalid email address'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self._runLocked(cb, function(cb) {
|
self._runLocked(cb, function(cb) {
|
||||||
var preferences = Model.Preferences.create({
|
var preferences = Model.Preferences.create({
|
||||||
walletId: self.walletId,
|
walletId: self.walletId,
|
||||||
|
|
|
@ -255,7 +255,7 @@ describe('Wallet service', function() {
|
||||||
storage: storage,
|
storage: storage,
|
||||||
blockchainExplorer: blockchainExplorer,
|
blockchainExplorer: blockchainExplorer,
|
||||||
mailer: mailer,
|
mailer: mailer,
|
||||||
email: {
|
emailOpts: {
|
||||||
from: 'bws@dummy.net',
|
from: 'bws@dummy.net',
|
||||||
}
|
}
|
||||||
}, done);
|
}, done);
|
||||||
|
@ -779,6 +779,21 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it.skip('should save preferences only for requesting wallet', function(done) {});
|
it.skip('should save preferences only for requesting wallet', function(done) {});
|
||||||
|
it('should validate email address', function(done) {
|
||||||
|
server.savePreferences({
|
||||||
|
email: ' '
|
||||||
|
}, function(err) {
|
||||||
|
should.exist(err);
|
||||||
|
err.message.should.contain('email');
|
||||||
|
server.savePreferences({
|
||||||
|
email: 'dummy@' + _.repeat('domain', 50),
|
||||||
|
}, function(err) {
|
||||||
|
should.exist(err);
|
||||||
|
err.message.should.contain('email');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getBalance', function() {
|
describe('#getBalance', function() {
|
||||||
|
|
Loading…
Reference in New Issue