@ -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 = s ervice . 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 < RequestPlex Settings> ( ) ;
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 ) ;
s ervice . SaveSettings ( oldSettings ) ;
}
else
{
var newModel = new SettingsModel
var newModel = new RequestPlex Settings
{
PlexAuthToken = model . user . authentication_token
} ;
s . SaveSettings ( newModel ) ;
s ervice . SaveSettings ( newModel ) ;
}