Using the IoC container now

pull/13/head
tidusjar 9 years ago
parent bee57b46ff
commit 6fd1e3ba32

@ -1,14 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: MovieBase.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 RequestPlex.Helpers;
namespace RequestPlex.Api
{
public abstract class MovieBase
{
protected string ApiKey = "b8eabaf5608b88d0298aa189dd90bf00";
private static readonly string Encrypted = "0T3QNSseexLO7n7UPiJvl70Y+KKnvbeTlsusl7Kwq0hPH0BHOuFNGwksNCjkwqWedyDdI/MJeUR4wtL4bIl0Z+//uHXEaYM/4H2pjeLbH5EWdUe5TTj1AhaIR5PQweamvcienRyFD/3YPCC/+qL5mHkKXBkPumMod3Zb/4yN0Ik=";
protected string ApiKey = StringCipher.Decrypt(Encrypted, "ApiKey");
protected string Url = "http://api.themoviedb.org/3";
}
}

@ -21,7 +21,7 @@ namespace RequestPlex.Api
Method = Method.POST,
};
request.AddHeader("X-Plex-Client-Identifier", "Test213");
request.AddHeader("X-Plex-Client-Identifier", "Test213"); // TODO need something unique to the users version/installation
request.AddHeader("X-Plex-Product", "Request Plex");
request.AddHeader("X-Plex-Version", "0.0.1");
request.AddHeader("Content-Type", "application/json");

@ -76,6 +76,10 @@
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
<Name>RequestPlex.Api.Interfaces</Name>
</ProjectReference>
<ProjectReference Include="..\RequestPlex.Helpers\RequestPlex.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>RequestPlex.Helpers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

@ -0,0 +1,35 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: ISettingsService.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 RequestPlex.Core
{
public interface ISettingsService<T>
{
T GetSettings();
bool SaveSettings(T model);
bool Delete(T model);
}
}

@ -41,6 +41,14 @@
<HintPath>..\packages\Nancy.Authentication.Forms.1.4.1\lib\net40\Nancy.Authentication.Forms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Omu.ValueInjecter, Version=3.1.1.0, Culture=neutral, PublicKeyToken=c7694541b0ac80e4, processorArchitecture=MSIL">
<HintPath>..\packages\valueinjecter.3.1.1.2\lib\net40\Omu.ValueInjecter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -51,7 +59,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ISettingsService.cs" />
<Compile Include="RequestService.cs" />
<Compile Include="SettingModels\RequestPlexSettings.cs" />
<Compile Include="SettingModels\Settings.cs" />
<Compile Include="SettingsService.cs" />
<Compile Include="SettingsServiceV2.cs" />
<Compile Include="Setup.cs" />
<Compile Include="UserIdentity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -61,6 +74,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RequestPlex.Helpers\RequestPlex.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>RequestPlex.Helpers</Name>
</ProjectReference>
<ProjectReference Include="..\RequestPlex.Store\RequestPlex.Store.csproj">
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
<Name>RequestPlex.Store</Name>

@ -0,0 +1,65 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: RequestService.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.Linq;
using RequestPlex.Store;
namespace RequestPlex.Core
{
public class RequestService
{
public RequestService(ISqliteConfiguration db, IRepository<RequestedModel> repo)
{
Db = db;
Repo = repo;
}
private ISqliteConfiguration Db { get; set; }
private IRepository<RequestedModel> Repo { get; set; }
public void AddRequest(int tmdbid, RequestType type)
{
var model = new RequestedModel
{
Tmdbid = tmdbid,
Type = type
};
Repo.Insert(model);
}
public bool CheckRequest(int tmdbid)
{
return Repo.GetAll().Any(x => x.Tmdbid == tmdbid);
}
public void DeleteRequest(int tmdbId)
{
var entity = Repo.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId);
Repo.Delete(entity);
}
}
}

@ -0,0 +1,33 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: Settings.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 RequestPlex.Core.SettingModels
{
public class Settings
{
public int Id { get; set; }
}
}

@ -1,8 +1,30 @@
using System;
using System.Collections.Generic;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SettingsService.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.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Data.Sqlite;
@ -12,21 +34,6 @@ namespace RequestPlex.Core
{
public class SettingsService
{
public void SaveSettings(SettingsModel model)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<SettingsModel>(db);
var existingSettings = repo.GetAll().FirstOrDefault();
if (existingSettings != null)
{
existingSettings = model;
repo.Update(existingSettings);
return;
}
repo.Insert(model);
}
public SettingsModel GetSettings()
{

@ -0,0 +1,114 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SettingsServiceV2.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 Newtonsoft.Json;
using Omu.ValueInjecter;
using RequestPlex.Core.SettingModels;
using RequestPlex.Helpers;
using RequestPlex.Store;
using RequestPlex.Store.Models;
namespace RequestPlex.Core
{
public class SettingsServiceV2<T> : ISettingsService<T>
where T : Settings, new()
{
public SettingsServiceV2(ISettingsRepository repo)
{
Repo = repo;
EntityName = typeof(T).Name;
}
private ISettingsRepository Repo { get; set; }
private string EntityName { get; set; }
public T GetSettings()
{
var result = Repo.Get(EntityName);
if (result == null)
{
return new T();
}
result.Content = DecryptSettings(result);
var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
var model = obj;
return model;
}
public bool SaveSettings(T model)
{
var entity = Repo.Get(EntityName);
if (entity == null)
{
var newEntity = model;
var settings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(newEntity, SerializerSettings.Settings) };
settings.Content = EncryptSettings(settings);
var insertResult = Repo.Insert(settings);
return insertResult != long.MinValue;
}
var modified = model;
modified.Id = entity.Id;
var globalSettings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(modified, SerializerSettings.Settings), Id = entity.Id };
globalSettings.Content = EncryptSettings(globalSettings);
var result = Repo.Update(globalSettings);
return result;
}
public bool Delete(T model)
{
var entity = Repo.Get(EntityName);
if (entity != null)
{
return Repo.Delete(entity);
}
// Entity does not exist so nothing to delete
return true;
}
private string EncryptSettings(GlobalSettings settings)
{
return StringCipher.Encrypt(settings.Content, settings.SettingsName);
}
private string DecryptSettings(GlobalSettings settings)
{
return StringCipher.Decrypt(settings.Content, settings.SettingsName);
}
}
}

@ -1,4 +1,30 @@
using System;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UserMapper.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 System.Linq;
using Mono.Data.Sqlite;
@ -13,11 +39,14 @@ namespace RequestPlex.Core
{
public class UserMapper : IUserMapper
{
public UserMapper(ISqliteConfiguration db)
{
Db = db;
}
private static ISqliteConfiguration Db { get; set; }
public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(db);
var repo = new UserRepository<UserModel>(Db);
var user = repo.Get(identifier.ToString());
@ -35,7 +64,7 @@ namespace RequestPlex.Core
public static Guid? ValidateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(db);
var repo = new UserRepository<UserModel>(Db);
var users = repo.GetAll();
var userRecord = users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase) && u.Password.Equals(password)); // TODO hashing
@ -50,7 +79,7 @@ namespace RequestPlex.Core
public static bool DoUsersExist()
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(db);
var repo = new UserRepository<UserModel>(Db);
var users = repo.GetAll();
return users.Any();
}
@ -58,7 +87,7 @@ namespace RequestPlex.Core
public static Guid? CreateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(db);
var repo = new UserRepository<UserModel>(Db);
var userModel = new UserModel { UserName = username, User = Guid.NewGuid().ToString(), Password = password };
repo.Insert(userModel);

@ -2,4 +2,6 @@
<packages>
<package id="Nancy" version="1.4.3" targetFramework="net452" />
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
<package id="valueinjecter" version="3.1.1.2" targetFramework="net452" />
</packages>

@ -49,6 +49,7 @@
<Compile Include="MemoryCacheProvider.cs" />
<Compile Include="ObjectCopier.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializerSettings.cs" />
<Compile Include="StringCipher.cs" />
</ItemGroup>
<ItemGroup>

@ -0,0 +1,45 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SerializerSettings.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.Runtime.Serialization.Formatters;
using Newtonsoft.Json;
namespace RequestPlex.Helpers
{
public static class SerializerSettings
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
Formatting = Formatting.None,
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
NullValueHandling = NullValueHandling.Ignore
};
}
}

@ -1,9 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: Entity.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 Dapper.Contrib.Extensions;
namespace RequestPlex.Store

@ -1,8 +1,31 @@
using System;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: GenericRepository.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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper.Contrib.Extensions;

@ -1,8 +1,30 @@
using System;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IRepository.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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RequestPlex.Store
{

@ -21,4 +21,11 @@ CREATE TABLE IF NOT EXISTS Requested
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Type INTEGER NOT NULL,
Tmdbid INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS GlobalSettings
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
SettingsName varchar(50) NOT NULL,
Content varchar(100) NOT NULL
);

@ -1,8 +1,32 @@
using System;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UserRepository.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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper.Contrib.Extensions;

@ -1,9 +1,16 @@
using Nancy;
using Mono.Data.Sqlite;
using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
using RequestPlex.Core;
using RequestPlex.Core.SettingModels;
using RequestPlex.Helpers;
using RequestPlex.Store;
using RequestPlex.Store.Models;
using RequestPlex.Store.Repository.NZBDash.DataAccessLayer.Repository;
using FormsAuthentication = Nancy.Authentication.Forms.FormsAuthentication;
@ -17,8 +24,21 @@ namespace RequestPlex.UI
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
base.ConfigureRequestContainer(container, context);
container.Register<IUserMapper, UserMapper>();
base.ConfigureRequestContainer(container, context);
container.Register<ISqliteConfiguration, DbConfiguration>(new DbConfiguration(new SqliteFactory()));
container.Register<ISettingsRepository, JsonRepository>();
container.Register<ICacheProvider, MemoryCacheProvider>();
container.Register<ISettingsService<RequestPlexSettings>, SettingsServiceV2<RequestPlexSettings>>();
}
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)

@ -1,16 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: AdminModule.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.Dynamic;
using System.Linq;
using Nancy;
using Nancy.Extensions;
using Nancy.ModelBinding;
using Nancy.Security;
using Newtonsoft.Json;
using RequestPlex.Api;
using RequestPlex.Core;
using RequestPlex.Core.SettingModels;
using RequestPlex.Store;
using RequestPlex.UI.Models;
@ -18,7 +40,7 @@ namespace RequestPlex.UI.Modules
{
public class AdminModule : NancyModule
{
public AdminModule()
public AdminModule(ISettingsService<RequestPlexSettings> service)
{
#if !DEBUG
this.RequiresAuthentication();
@ -28,8 +50,8 @@ namespace RequestPlex.UI.Modules
dynamic model = new ExpandoObject();
model.Errored = Request.Query.error.HasValue;
model.Port = null;
var s = new SettingsService();
var settings = s.GetSettings();
var settings = service.GetSettings();
if (settings != null)
{
model.Port = settings.Port;
@ -41,10 +63,9 @@ namespace RequestPlex.UI.Modules
Post["admin/"] = _ =>
{
var model = this.Bind<SettingsModel>();
var model = this.Bind<RequestPlexSettings>();
var s = new SettingsService();
s.SaveSettings(model);
service.SaveSettings(model);
return Context.GetRedirect("~/admin");
@ -61,20 +82,19 @@ namespace RequestPlex.UI.Modules
var plex = new PlexApi();
var model = plex.GetToken(user.username, user.password);
var s = new SettingsService();
var oldSettings = s.GetSettings();
var oldSettings = service.GetSettings();
if (oldSettings != null)
{
oldSettings.PlexAuthToken = model.user.authentication_token;
s.SaveSettings(oldSettings);
service.SaveSettings(oldSettings);
}
else
{
var newModel = new SettingsModel
var newModel = new RequestPlexSettings
{
PlexAuthToken = model.user.authentication_token
};
s.SaveSettings(newModel);
service.SaveSettings(newModel);
}

@ -1,12 +1,28 @@
using Nancy;
using RequestPlex.Core;
using RequestPlex.Core.SettingModels;
namespace RequestPlex.UI.Modules
{
public class RequestsModule : NancyModule
{
public RequestsModule()
public RequestsModule(ISettingsService<RequestPlexSettings> s)
{
Get["requests/"] = _ => "Hello!";
Get["requests/test"] = _ =>
{
var se = new RequestPlexSettings
{
PlexAuthToken = "abc",
Port = 2344,
UserAuthentication = false
};
s.SaveSettings(se);
var a = s.GetSettings();
return "Hi!";
};
}
}
}

@ -49,7 +49,6 @@ namespace RequestPlex.UI.Modules
private Response SearchMovie(string searchTerm)
{
var s = new SettingsService();
var api = new TheMovieDbApi();
var movies = api.SearchMovie(searchTerm);
var result = movies.Result;

@ -2,9 +2,15 @@
using Microsoft.Owin.Hosting;
using Mono.Data.Sqlite;
using Nancy.Hosting.Self;
using RequestPlex.Core;
using RequestPlex.Core.SettingModels;
using RequestPlex.Helpers;
using RequestPlex.Store;
using RequestPlex.Store.Repository.NZBDash.DataAccessLayer.Repository;
namespace RequestPlex.UI
{
@ -16,7 +22,7 @@ namespace RequestPlex.UI
var s = new Setup();
s.SetupDb();
var service = new SettingsService();
var service = new SettingsServiceV2<RequestPlexSettings>(new JsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var settings = service.GetSettings();
if (settings != null)

@ -50,6 +50,10 @@
<HintPath>..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Assemblies\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.1.4.1\lib\net40\Nancy.dll</HintPath>
</Reference>
@ -71,10 +75,6 @@
<Reference Include="Nancy.ViewEngines.Razor">
<HintPath>..\packages\Nancy.Viewengines.Razor.1.4.1\lib\net40\Nancy.ViewEngines.Razor.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
@ -85,6 +85,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
@ -208,6 +209,10 @@
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
<Name>RequestPlex.Core</Name>
</ProjectReference>
<ProjectReference Include="..\RequestPlex.Helpers\RequestPlex.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>RequestPlex.Helpers</Name>
</ProjectReference>
<ProjectReference Include="..\RequestPlex.Store\RequestPlex.Store.csproj">
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
<Name>RequestPlex.Store</Name>

@ -1,4 +1,6 @@
using Owin;
using System;
using Owin;
namespace RequestPlex.UI
{
@ -6,7 +8,16 @@ namespace RequestPlex.UI
{
public void Configuration(IAppBuilder app)
{
try
{
app.UseNancy();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
}
}

@ -44,7 +44,7 @@
<input type="text" class="form-control" id="username" name="Username" placeholder="Username">
</div>
<div class="col-lg-4 col-lg-push-1">
<input type="password" class="form-control" id="password" name="Username" placeholder="Password">
<input type="password" class="form-control" id="password" name="Password" placeholder="Password">
</div>
</div>
<div class="form-group">
@ -60,8 +60,7 @@
</div>
</div>
<small>Current users that are allowed to authenticate: </small>
<select id="users" multiple="" class="form-control">
</select>
<select id="users" multiple="" class="form-control"></select>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
@ -69,10 +68,10 @@
</div>
</div>
<br/>
<br/>
<br/>
<br/>
<br />
<br />
<br />
<br />
<div>
<small class="col-lg-10 col-lg-offset-2">Please note, you will have to restart after changing these settings.</small>
</div>
@ -98,9 +97,11 @@
<script>
$(function () {
loadUserList();
if ($('#PlexAuthToken')) {
loadUserList();
}
$('#refreshUsers').click(function() {
$('#refreshUsers').click(function () {
loadUserList();
});

@ -10,7 +10,6 @@
<package id="Nancy.Hosting.Self" version="1.4.1" requireReinstallation="true" />
<package id="Nancy.Owin" version="1.4.1" targetFramework="net452" />
<package id="Nancy.Viewengines.Razor" version="1.4.1" requireReinstallation="true" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
<package id="RestSharp" version="105.2.3" targetFramework="net452" />
<package id="TMDbLib" version="0.9.0.0-alpha" targetFramework="net452" />

Loading…
Cancel
Save