From c9fcde3bbb2bec00b47982de550735644f067cec Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 4 Apr 2012 15:29:55 -0700 Subject: [PATCH] Fix: Email notification testing. --- NzbDrone.Core/Providers/SmtpProvider.cs | 2 +- NzbDrone.Web/Controllers/CommandController.cs | 4 +- NzbDrone.Web/Scripts/NzbDrone/settings.js | 90 +++++++++++++++++++ .../Views/Settings/Notifications.cshtml | 89 ------------------ 4 files changed, 93 insertions(+), 92 deletions(-) diff --git a/NzbDrone.Core/Providers/SmtpProvider.cs b/NzbDrone.Core/Providers/SmtpProvider.cs index c22f13b9c..70b5edb23 100644 --- a/NzbDrone.Core/Providers/SmtpProvider.cs +++ b/NzbDrone.Core/Providers/SmtpProvider.cs @@ -90,7 +90,7 @@ namespace NzbDrone.Core.Providers credentials = new NetworkCredential(username, password); //Send the email - return Send(email, _configProvider.SmtpServer, _configProvider.SmtpPort, _configProvider.SmtpUseSsl, credentials); + return Send(email, server, port, ssl, credentials); } //TODO: make this throw instead of return false. diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 03487435b..959780f05 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -68,10 +68,10 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public JsonResult SendTestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses) + public JsonResult TestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses) { if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses)) - JsonNotificationResult.Info("Successful", "Test email sent."); + return JsonNotificationResult.Info("Successful", "Test email sent."); return JsonNotificationResult.Oops("Couldn't send Email, please check your settings"); } diff --git a/NzbDrone.Web/Scripts/NzbDrone/settings.js b/NzbDrone.Web/Scripts/NzbDrone/settings.js index 802d9e289..60add8e1e 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/settings.js +++ b/NzbDrone.Web/Scripts/NzbDrone/settings.js @@ -8,6 +8,7 @@ $('#MultiEpisodeStyle').live('change', function () { createExamples(); }); var testProwlUrl = '../Command/TestProwl'; var testSabUrl = '../Command/TestSabnzbd'; +var testEmailUrl = '../Command/TestEmail'; function createExamples() { @@ -133,4 +134,93 @@ function testSabnzbd(event) { }); event.preventDefault(); +} + +//Twitter +getAuthorizationUrl = '../Command/GetTwitterAuthorization'; +verifyAuthorizationUrl = '../Command/VerifyTwitterAuthorization'; + +function requestTwitterAuthorization() { + $.ajax({ + type: "GET", + url: getAuthorizationUrl, + error: function (req, status, error) { + alert("Sorry! We could get Twitter Authorization at this time. " + error); + }, + success: function (data, textStatus, jqXHR) { + if (data.IsMessage) + return false; + + $('#authorizationRequestToken').val(data.Token); + window.open(data.Url); + } + }); +} + +function verifyTwitterAuthorization() { + var token = $('#authorizationRequestToken').val(); + var verifier = $('#twitterVerification').val(); + + $.ajax({ + type: "GET", + url: verifyAuthorizationUrl, + data: jQuery.param({ token: token, verifier: verifier }), + error: function (req, status, error) { + alert("Sorry! We could verify Twitter Authorization at this time. " + error); + } + }); +} + +//SMTP +function testSmtpSettings() { + //Get the variables + var server = $('#SmtpServer').val(); + var port = $('#SmtpPort').val(); + var ssl = $('#SmtpUseSsl').val(); + var username = $('#SmtpUsername').val(); + var password = $('#SmtpPassword').val(); + var fromAddress = $('#SmtpFromAddress').val(); + var toAddresses = $('#SmtpToAddresses').val(); + + //Send the data! + $.ajax({ + type: "POST", + url: testEmailUrl, + data: jQuery.param({ + server: server, + port: port, + ssl: ssl, + username: username, + password: password, + fromAddress: fromAddress, + toAddresses: toAddresses + }), + error: function (req, status, error) { + alert("Sorry! We could send a test email at this time. " + error); + } + }); + + return false; +} + +//Growl +function registerGrowl() { + //Get the variables + var host = $('#GrowlHost').val(); + var password = $('#GrowlPassword').val(); + + //Send the data! + $.ajax({ + type: "POST", + url: '../Command/RegisterGrowl', + data: jQuery.param({ + host: host, + password: password + }), + error: function (req, status, error) { + alert("Sorry! We could send a test email at this time. " + error); + } + }); + + return false; } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Notifications.cshtml b/NzbDrone.Web/Views/Settings/Notifications.cshtml index d750aa10d..9dc3b676f 100644 --- a/NzbDrone.Web/Views/Settings/Notifications.cshtml +++ b/NzbDrone.Web/Views/Settings/Notifications.cshtml @@ -88,93 +88,4 @@ if ($(container).children('.input-validation-error').length == 0) $(container).prev('h3.ui-accordion-header').removeClass('validation-error'); }); - - //Twitter - getAuthorizationUrl = '../Command/GetTwitterAuthorization'; - verifyAuthorizationUrl = '../Command/VerifyTwitterAuthorization'; - - function requestTwitterAuthorization() { - $.ajax({ - type: "GET", - url: getAuthorizationUrl, - error: function (req, status, error) { - alert("Sorry! We could get Twitter Authorization at this time. " + error); - }, - success: function (data, textStatus, jqXHR) { - if (data.IsMessage) - return false; - - $('#authorizationRequestToken').val(data.Token); - window.open(data.Url); - } - }); - } - - function verifyTwitterAuthorization() { - var token = $('#authorizationRequestToken').val(); - var verifier = $('#twitterVerification').val(); - - $.ajax({ - type: "GET", - url: verifyAuthorizationUrl, - data: jQuery.param({ token: token, verifier: verifier }), - error: function (req, status, error) { - alert("Sorry! We could verify Twitter Authorization at this time. " + error); - } - }); - } - - //SMTP - function testSmtpSettings() { - //Get the variables - var server = $('#SmtpServer').val(); - var port = $('#SmtpPort').val(); - var ssl = $('#SmtpUseSsl').val(); - var username = $('#SmtpUsername').val(); - var password = $('#SmtpPassword').val(); - var fromAddress = $('#SmtpFromAddress').val(); - var toAddresses = $('#SmtpToAddresses').val(); - - //Send the data! - $.ajax({ - type: "POST", - url: '../Command/SendTestEmail', - data: jQuery.param({ - server: server, - port: port, - ssl: ssl, - username: username, - password: password, - fromAddress: fromAddress, - toAddresses: toAddresses - }), - error: function (req, status, error) { - alert("Sorry! We could send a test email at this time. " + error); - } - }); - - return false; - } - - //Growl - function registerGrowl() { - //Get the variables - var host = $('#GrowlHost').val(); - var password = $('#GrowlPassword').val(); - - //Send the data! - $.ajax({ - type: "POST", - url: '../Command/RegisterGrowl', - data: jQuery.param({ - host: host, - password: password - }), - error: function (req, status, error) { - alert("Sorry! We could send a test email at this time. " + error); - } - }); - - return false; - }