add email validation
This commit is contained in:
parent
910a1c8ddc
commit
a643819b46
|
@ -40,7 +40,7 @@ var config = {
|
|||
},
|
||||
},
|
||||
// To use email notifications uncomment this:
|
||||
email: {
|
||||
emailOpts: {
|
||||
host: 'localhost',
|
||||
port: 25,
|
||||
ignoreTLS: true,
|
||||
|
|
|
@ -33,13 +33,13 @@ var EMAIL_TYPES = {
|
|||
function EmailService(opts) {
|
||||
$.checkArgument(opts);
|
||||
|
||||
opts.email = opts.email || {};
|
||||
opts.emailOpts = opts.emailOpts || {};
|
||||
|
||||
this.storage = opts.storage;
|
||||
this.lock = opts.lock;
|
||||
this.mailer = opts.mailer || nodemailer.createTransport(opts.email);
|
||||
this.subjectPrefix = opts.email.subjectPrefix || '[Wallet service]';
|
||||
this.from = opts.email.from;
|
||||
this.mailer = opts.mailer || nodemailer.createTransport(opts.emailOpts);
|
||||
this.subjectPrefix = opts.emailOpts.subjectPrefix || '[Wallet service]';
|
||||
this.from = opts.emailOpts.from;
|
||||
|
||||
$.checkState(this.mailer);
|
||||
$.checkState(this.from);
|
||||
|
|
|
@ -87,7 +87,7 @@ WalletService.initialize = function(opts, cb) {
|
|||
lock: lock,
|
||||
storage: storage,
|
||||
mailer: opts.mailer,
|
||||
email: opts.email,
|
||||
emailOpts: opts.emailOpts,
|
||||
});
|
||||
return cb();
|
||||
};
|
||||
|
@ -448,6 +448,12 @@ WalletService.prototype.savePreferences = function(opts, cb) {
|
|||
|
||||
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) {
|
||||
var preferences = Model.Preferences.create({
|
||||
walletId: self.walletId,
|
||||
|
|
|
@ -255,7 +255,7 @@ describe('Wallet service', function() {
|
|||
storage: storage,
|
||||
blockchainExplorer: blockchainExplorer,
|
||||
mailer: mailer,
|
||||
email: {
|
||||
emailOpts: {
|
||||
from: 'bws@dummy.net',
|
||||
}
|
||||
}, done);
|
||||
|
@ -779,6 +779,21 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue