Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 9eadc58

Browse files
committed
Add SMTP checking code to view
1 parent f284db7 commit 9eadc58

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

js/views/settingsVw.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var __ = require('underscore'),
1616
chosen = require('../utils/chosen.jquery.min.js'),
1717
setTheme = require('../utils/setTheme.js'),
1818
saveToAPI = require('../utils/saveToAPI'),
19+
SMTPConnection = require('smtp-connection'),
1920
MediumEditor = require('medium-editor'),
2021
validateMediumEditor = require('../utils/validateMediumEditor'),
2122
getBTPrice = require('../utils/getBitcoinPrice');
@@ -44,6 +45,7 @@ module.exports = Backbone.View.extend({
4445
'click .js-saveModerator': 'saveModeratorClick',
4546
'click .js-cancelAdvanced': 'cancelView',
4647
'click .js-saveAdvanced': 'saveAdvancedClick',
48+
'click .js-testSMTP': 'testSMTPClick',
4749
'click .js-changeServerSettings': 'launchServerConfig',
4850
'change .js-settingsThemeSelection': 'themeClick',
4951
'click .js-settingsAddressDelete': 'addressDelete',
@@ -659,6 +661,10 @@ module.exports = Backbone.View.extend({
659661
this.saveAdvanced();
660662
},
661663

664+
testSMTPClick: function() {
665+
this.testSMTP();
666+
},
667+
662668
saveGeneral: function() {
663669
var self = this,
664670
form = this.$("#generalForm"),
@@ -970,6 +976,51 @@ module.exports = Backbone.View.extend({
970976
});
971977
},
972978

979+
testSMTP: function(){
980+
var hostport = $('#advancedForm').find('input[name="smtp_server"]').val();
981+
hostport = hostport.split(':');
982+
983+
$('#testSMTPButton').addClass('loading');
984+
985+
var connection = new SMTPConnection({
986+
host: hostport[0],
987+
port: hostport[1]
988+
});
989+
990+
connection.on('error', function(){
991+
$('#testSMTPButton').removeClass('loading');
992+
messageModal.show(
993+
window.polyglot.t('errorMessages.smtpServerError'),
994+
window.polyglot.t('errorMessages.noSMTPConnection')
995+
);
996+
}
997+
);
998+
999+
connection.connect(function() {
1000+
1001+
var username = $('#advancedForm').find('input[name="smtp_username"]').val();
1002+
var password = $('#advancedForm').find('input[name="smtp_password"]').val();
1003+
1004+
connection.login({
1005+
user: username,
1006+
pass: password
1007+
}, function(err) {
1008+
if(err) {
1009+
messageModal.show(
1010+
window.polyglot.t('errorMessages.smtpServerError'),
1011+
window.polyglot.t('errorMessages.badSMTPAuthentication')
1012+
);
1013+
} else {
1014+
messageModal.show(
1015+
window.polyglot.t('errorMessages.smtpServerSuccess'),
1016+
window.polyglot.t('errorMessages.goodSMTPAuthentication')
1017+
);
1018+
}
1019+
$('#testSMTPButton').removeClass('loading');
1020+
})
1021+
})
1022+
},
1023+
9731024
saveAdvanced: function(){
9741025
var self = this,
9751026
form = this.$("#advancedForm"),

0 commit comments

Comments
 (0)