#387 trim the spaces from the api key. Tidied up the setting models a bit.

pull/470/head
tidusjar 9 years ago
parent c5ad97780f
commit 6392ee0bde

@ -81,6 +81,7 @@
<Compile Include="Models\StatusModel.cs" />
<Compile Include="Models\UserProperties.cs" />
<Compile Include="SettingModels\AuthenticationSettings.cs" />
<Compile Include="SettingModels\ExternalSettings.cs" />
<Compile Include="SettingModels\HeadphonesSettings.cs" />
<Compile Include="SettingModels\LandingPageSettings.cs" />
<Compile Include="SettingModels\NotificationSettings.cs" />

@ -31,10 +31,11 @@ using Newtonsoft.Json;
namespace PlexRequests.Core.SettingModels
{
public class AuthenticationSettings : Settings
public sealed class AuthenticationSettings : Settings
{
public bool UserAuthentication { get; set; }
public bool UsePassword { get; set; }
[JsonProperty("PlexAuthToken")]
[Obsolete("This should be migrated over into the Plex Settings and then removed in the next release")]
public string OldPlexAuthToken { get; set; }

@ -24,38 +24,14 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public class CouchPotatoSettings : Settings
public sealed class CouchPotatoSettings : ExternalSettings
{
public bool Enabled { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Ssl { get; set; }
public string ProfileId { get; set; }
public string SubDir { get; set; }
public string Username { get; set; }
public string Password { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
}
}

@ -26,7 +26,7 @@
#endregion
namespace PlexRequests.Core.SettingModels
{
public class EmailNotificationSettings : NotificationSettings
public sealed class EmailNotificationSettings : NotificationSettings
{
public string EmailHost { get; set; }
public string EmailPassword { get; set; }

@ -0,0 +1,57 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: ExternalSettings.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 System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public abstract class ExternalSettings : Settings
{
public bool Ssl { get; set; }
public string SubDir { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
[JsonIgnore]
public virtual Uri FullUri
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
}
}

@ -24,35 +24,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public class HeadphonesSettings : Settings
public sealed class HeadphonesSettings : ExternalSettings
{
public bool Enabled { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Ssl { get; set; }
public string SubDir { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
}
}

@ -30,7 +30,7 @@ using Newtonsoft.Json;
namespace PlexRequests.Core.SettingModels
{
public class LandingPageSettings : Settings
public sealed class LandingPageSettings : Settings
{
public bool Enabled { get; set; }
public bool BeforeLogin { get; set; }

@ -25,11 +25,10 @@
// ************************************************************************/
#endregion
using NLog;
namespace PlexRequests.Core.SettingModels
{
public class LogSettings : Settings
public sealed class LogSettings : Settings
{
public int Level { get; set; }
}

@ -30,7 +30,7 @@ using System.Collections.Generic;
namespace PlexRequests.Core.SettingModels
{
public class PlexRequestSettings : Settings
public sealed class PlexRequestSettings : Settings
{
public PlexRequestSettings()
{

@ -24,36 +24,12 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public class PlexSettings : Settings
public sealed class PlexSettings : ExternalSettings
{
public string Ip { get; set; }
public int Port { get; set; }
public bool Ssl { get; set; }
public string SubDir { get; set; }
public bool AdvancedSearch { get; set; }
public string PlexAuthToken { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
}
}

@ -1,9 +1,35 @@
namespace PlexRequests.Core.SettingModels
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PushBulletNotificationSettings.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
namespace PlexRequests.Core.SettingModels
{
public class PushbulletNotificationSettings : NotificationSettings
public sealed class PushbulletNotificationSettings : NotificationSettings
{
public bool Enabled { get; set; }
public string AccessToken { get; set; }
public string DeviceIdentifier { get; set; }
public bool Enabled { get; set; }
}
}

@ -1,9 +1,35 @@
namespace PlexRequests.Core.SettingModels
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PushoverNotificationSettings.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
namespace PlexRequests.Core.SettingModels
{
public class PushoverNotificationSettings : NotificationSettings
public sealed class PushoverNotificationSettings : NotificationSettings
{
public bool Enabled { get; set; }
public string AccessToken { get; set; }
public bool Enabled { get; set; }
public string UserToken { get; set; }
}
}

@ -26,7 +26,7 @@
#endregion
namespace PlexRequests.Core.SettingModels
{
public class ScheduledJobsSettings : Settings
public sealed class ScheduledJobsSettings : Settings
{
public ScheduledJobsSettings()
{

@ -24,54 +24,27 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
using System.Collections.Generic;
namespace PlexRequests.Core.SettingModels
{
public class SickRageSettings : Settings
public sealed class SickRageSettings : ExternalSettings
{
public bool Enabled { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public string QualityProfile { get; set; }
public bool Ssl { get; set; }
public string SubDir { get; set; }
public Dictionary<string, string> Qualities
{
get
{
return new Dictionary<string, string>() {
{ "default", "Use Deafult" },
{ "sdtv", "SD TV" },
{ "sddvd", "SD DVD" },
{ "hdtv", "HD TV" },
{ "rawhdtv", "Raw HD TV" },
{ "hdwebdl", "HD Web DL" },
{ "fullhdwebdl", "Full HD Web DL" },
{ "hdbluray", "HD Bluray" },
{ "fullhdbluray", "Full HD Bluray" }
};
}
}
[JsonIgnore]
public Uri FullUri
public Dictionary<string, string> Qualities => new Dictionary<string, string>
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
{ "default", "Use Deafult" },
{ "sdtv", "SD TV" },
{ "sddvd", "SD DVD" },
{ "hdtv", "HD TV" },
{ "rawhdtv", "Raw HD TV" },
{ "hdwebdl", "HD Web DL" },
{ "fullhdwebdl", "Full HD Web DL" },
{ "hdbluray", "HD Bluray" },
{ "fullhdbluray", "Full HD Bluray" }
};
}
}

@ -4,7 +4,7 @@ using Newtonsoft.Json;
namespace PlexRequests.Core.SettingModels
{
public class SlackNotificationSettings : NotificationSettings
public sealed class SlackNotificationSettings : NotificationSettings
{
public bool Enabled { get; set; }
public string WebhookUrl { get; set; }

@ -24,38 +24,15 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public class SonarrSettings : Settings
public sealed class SonarrSettings : ExternalSettings
{
public bool Enabled { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public string QualityProfile { get; set; }
public bool SeasonFolders { get; set; }
public string RootPath { get; set; }
public bool Ssl { get; set; }
public string SubDir { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
if (!string.IsNullOrEmpty(SubDir))
{
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
return formattedSubDir;
}
var formatted = Ip.ReturnUri(Port, Ssl);
return formatted;
}
}
}
}

@ -30,7 +30,6 @@ using Newtonsoft.Json;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
@ -46,8 +45,8 @@ namespace PlexRequests.Core
EntityName = typeof(T).Name;
}
private ISettingsRepository Repo { get; set; }
private string EntityName { get; set; }
private ISettingsRepository Repo { get; }
private string EntityName { get; }
public T GetSettings()
{

@ -171,7 +171,7 @@ namespace PlexRequests.UI.Modules
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
Post["/cpprofiles", true] = async (x,ct) => await GetCpProfiles();
Post["/cpapikey", true] = async (x,ct) => await GetCpApiKey();
Post["/cpapikey"] = x => GetCpApiKey();
Get["/emailnotification"] = _ => EmailNotifications();
Post["/emailnotification"] = _ => SaveEmailNotifications();
@ -362,6 +362,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(valid.SendJsonError());
}
couchPotatoSettings.ApiKey = couchPotatoSettings.ApiKey.Trim();
var result = CpService.SaveSettings(couchPotatoSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for CouchPotato!" }
@ -413,6 +414,7 @@ namespace PlexRequests.UI.Modules
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" });
}
sonarrSettings.ApiKey = sonarrSettings.ApiKey.Trim();
var result = SonarrService.SaveSettings(sonarrSettings);
return Response.AsJson(result
@ -442,6 +444,7 @@ namespace PlexRequests.UI.Modules
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Sonarr is enabled, we cannot enable Sonarr and SickRage" });
}
sickRageSettings.ApiKey = sickRageSettings.ApiKey.Trim();
var result = SickRageService.SaveSettings(sickRageSettings);
return Response.AsJson(result
@ -697,7 +700,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(profiles);
}
private async Task<Response> GetCpApiKey()
private Response GetCpApiKey()
{
var settings = this.Bind<CouchPotatoSettings>();
@ -767,7 +770,7 @@ namespace PlexRequests.UI.Modules
Log.Info("Error validating Headphones settings, message: {0}", error.Message);
return Response.AsJson(error);
}
settings.ApiKey = settings.ApiKey.Trim();
var result = HeadphonesService.SaveSettings(settings);
Log.Info("Saved headphones settings, result: {0}", result);

Loading…
Cancel
Save