Added validation to the Email settings, also increased the availability checker from 2 minutes to 5

pull/23/head
tidusjar 9 years ago
parent 752d8bb66e
commit aa5304b8dd

@ -4,7 +4,6 @@
{
public string EmailHost { get; set; }
public int EmailPort { get; set; }
public bool EmailAuthentication { get; set; }
public string RecipientEmail { get; set; }
public string EmailUsername { get; set; }
public string EmailPassword { get; set; }

@ -26,8 +26,6 @@
#endregion
using System;
using System.Reactive.Linq;
using System.Runtime.Remoting.Messaging;
using System.Threading.Tasks;
using System.Web.Hosting;
using FluentScheduler;
@ -76,7 +74,7 @@ namespace PlexRequests.Services
public void Stop(bool immediate)
{
throw new System.NotImplementedException();
HostingEnvironment.UnregisterObject(this);
}
}

@ -30,8 +30,6 @@ namespace PlexRequests.Services.Interfaces
{
public interface IIntervals
{
TimeSpan CriticalNotification { get; } // notification interval for critical load
TimeSpan Measurement { get; } // how often to measure
TimeSpan Notification { get; } // notification interval for high load
}
}

@ -32,9 +32,7 @@ namespace PlexRequests.Services
{
public class UpdateInterval : IIntervals
{
public TimeSpan Measurement => TimeSpan.FromSeconds(1);
public TimeSpan CriticalNotification { get; }
public TimeSpan Notification => TimeSpan.FromMinutes(2);
public TimeSpan Notification => TimeSpan.FromMinutes(5);
}
}

@ -294,6 +294,11 @@ namespace PlexRequests.UI.Modules
private Response SaveEmailNotifications()
{
var settings = this.Bind<EmailNotificationSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
Log.Trace(settings.DumpJson());
var result = EmailService.SaveSettings(settings);

@ -161,6 +161,7 @@
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\ValidationHelper.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" />
<Compile Include="Validators\CouchPotatoValidator.cs" />
<Compile Include="Validators\PlexValidator.cs" />
<Compile Include="Validators\SonarrValidator.cs" />

@ -0,0 +1,46 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrValidator.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using FluentValidation;
using PlexRequests.Core.SettingModels;
namespace PlexRequests.UI.Validators
{
public class EmailNotificationSettingsValidator : AbstractValidator<EmailNotificationSettings>
{
public EmailNotificationSettingsValidator()
{
RuleFor(request => request.EmailHost).NotEmpty().WithMessage("You must specify a Host name.");
RuleFor(request => request.EmailPort).NotEmpty().WithMessage("You must specify a Port.");
RuleFor(request => request.RecipientEmail).NotEmpty().WithMessage("You must specify a Recipient.");
RuleFor(request => request.RecipientEmail).EmailAddress().WithMessage("You must specify a valid Recipient.");
RuleFor(request => request.EmailUsername).EmailAddress().WithMessage("You must specify a valid Username.");
RuleFor(request => request.EmailUsername).NotEmpty().WithMessage("You must specify a Username.");
RuleFor(request => request.EmailPassword).NotEmpty().WithMessage("You must specify a valid password.");
}
}
}

@ -52,21 +52,6 @@
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
@if (Model.EmailAuthentication)
{
<input type="checkbox" id="EmailAuthentication" name="EmailAuthentication" checked="checked"><text>Authenticate</text>
}
else
{
<input type="checkbox" id="EmailAuthentication" name="EmailAuthentication"><text>Authenticate</text>
}
</label>
</div>
</div>
<div class="form-group">
<label for="EmailUsername" class="control-label">Username</label>
<div>
@ -84,10 +69,45 @@
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary-outline">Submit</button>
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function () {
$('#save').click(function (e) {
e.preventDefault();
var port = $('#EmailPort').val();
if (isNaN(port)) {
generateNotify("You must specify a valid Port.", "warning");
return;
}
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: $form.prop("action"),
dataType: "json",
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
});
</script>
Loading…
Cancel
Save