diff --git a/PlexRequests.Api/ApiRequest.cs b/PlexRequests.Api/ApiRequest.cs index f5f573066..e1a67e852 100644 --- a/PlexRequests.Api/ApiRequest.cs +++ b/PlexRequests.Api/ApiRequest.cs @@ -39,7 +39,7 @@ namespace PlexRequests.Api { public class ApiRequest : IApiRequest { - + /// <summary> /// An API request handler /// </summary> @@ -54,7 +54,7 @@ namespace PlexRequests.Api var response = client.Execute<T>(request); if (response.ErrorException != null) - { + { var message = "Error retrieving response. Check inner details for more info."; throw new ApplicationException(message, response.ErrorException); } @@ -75,7 +75,8 @@ namespace PlexRequests.Api throw new ApplicationException(message, response.ErrorException); } - return Deserialize<T>(response.Content); + var result = Deserialize<T>(response.Content); + return result; } public T Deserialize<T>(string input) @@ -83,8 +84,15 @@ namespace PlexRequests.Api { var ser = new XmlSerializer(typeof(T)); - using (var sr = new StringReader(input)) - return (T)ser.Deserialize(sr); + try + { + using (var sr = new StringReader(input)) + return (T)ser.Deserialize(sr); + } + catch (InvalidOperationException) + { + return null; + } } } } diff --git a/PlexRequests.Api/Models/PlexError.cs b/PlexRequests.Api/Models/PlexError.cs new file mode 100644 index 000000000..7dc696fc9 --- /dev/null +++ b/PlexRequests.Api/Models/PlexError.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexError.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.Xml.Serialization; + +namespace PlexRequests.Api.Models +{ + [XmlRoot(ElementName = "errors")] + public class PlexError + { + [XmlElement(ElementName = "error")] + public string Error { get; set; } + + } +} diff --git a/PlexRequests.Api/PlexRequests.Api.csproj b/PlexRequests.Api/PlexRequests.Api.csproj index 7c3aaae4d..911371a69 100644 --- a/PlexRequests.Api/PlexRequests.Api.csproj +++ b/PlexRequests.Api/PlexRequests.Api.csproj @@ -62,6 +62,7 @@ <ItemGroup> <Compile Include="ApiRequest.cs" /> <Compile Include="Models\PlexAuthentication.cs" /> + <Compile Include="Models\PlexError.cs" /> <Compile Include="Models\PlexFriends.cs" /> <Compile Include="Models\PlexUserRequest.cs" /> <Compile Include="Models\Tv\Authentication.cs" /> diff --git a/PlexRequests.UI/Content/custom.css b/PlexRequests.UI/Content/custom.css index 66b9c0ba4..e8f009e7f 100644 --- a/PlexRequests.UI/Content/custom.css +++ b/PlexRequests.UI/Content/custom.css @@ -1,11 +1,20 @@ @media (min-width: 768px ) { - .row { - position: relative; - } + .row { + position: relative; + } - .bottom-align-text { - position: absolute; - bottom: 0; - right: 0; - } -} \ No newline at end of file + .bottom-align-text { + position: absolute; + bottom: 0; + right: 0; + } +} + +.multiSelect { + background-color: #4e5d6c; +} + +.form-control-custom { + background-color: #4e5d6c !important; + color: white !important; +} diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index 007fec367..a69c996d0 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -117,6 +117,12 @@ namespace PlexRequests.UI.Modules var plex = new PlexApi(); var model = plex.GetToken(user.username, user.password); + + if (model.user == null) + { + return Response.AsJson(new { Result = false, Message = "Incorrect username or password!" }); + } + var oldSettings = AuthService.GetSettings(); if (oldSettings != null) { @@ -132,15 +138,22 @@ namespace PlexRequests.UI.Modules AuthService.SaveSettings(newModel); } - return Response.AsJson(new {Result = true, AuthToken = model.user.authentication_token}); + return Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token }); } private Response GetUsers() { var token = AuthService.GetSettings().PlexAuthToken; + if (token == null) + { + return Response.AsJson(string.Empty); + } var api = new PlexApi(); var users = api.GetUsers(token); + if (users == null) + { return Response.AsJson(string.Empty); } + var usernames = users.User.Select(x => x.Username); return Response.AsJson(usernames); //TODO usernames are not populated. } @@ -162,6 +175,6 @@ namespace PlexRequests.UI.Modules return Context.GetRedirect("~/admin/couchpotato"); } - + } } \ No newline at end of file diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 6ebc947a3..48fde4c94 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -130,7 +130,7 @@ namespace PlexRequests.UI // Step 5. Activate the configuration LogManager.Configuration = config; } - catch (Exception e) + catch (Exception ) { throw; diff --git a/PlexRequests.UI/Views/Admin/Authentication.cshtml b/PlexRequests.UI/Views/Admin/Authentication.cshtml index 6a97851ee..2ab4930da 100644 --- a/PlexRequests.UI/Views/Admin/Authentication.cshtml +++ b/PlexRequests.UI/Views/Admin/Authentication.cshtml @@ -1,7 +1,7 @@ @Html.Partial("/Admin/_Sidebar") <div class="col-sm-8"> - <form class="form-horizontal" method="POST" action="/admin/SaveAuthentication" id="mainForm"> + <form class="form-horizontal" method="POST" action="/admin/authentication" id="mainForm"> <fieldset> <legend>Authentication Settings</legend> @@ -40,17 +40,17 @@ <div class="form-group"> <label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label> <div class="col-lg-10"> - <input type="text" class="form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken"> + <input type="text" class="form-control-custom form-control " id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken"> </div> </div> <div class="form-group"> <label for="username" class="col-lg-2 control-label">Username and Password</label> <div class="col-lg-4"> - <input type="text" class="form-control" id="username" name="Username" placeholder="Username"> + <input type="text" class="form-control form-control-custom" 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="Password" placeholder="Password"> + <div class="col-lg-4 col-lg-push-2"> + <input type="password" class="form-control form-control-custom" id="password" name="Password" placeholder="Password"> </div> </div> <div class="form-group"> @@ -66,20 +66,16 @@ <br /> <br /> <div class="form-group"> - <select id="users" multiple="" class="col-lg-10 col-lg-offset-2"></select> + <select id="users" multiple="" class="col-lg-10 col-lg-offset-2 form-control-custom "></select> </div> <div class="form-group"> - <br /> - <br /> + <div class="col-lg-10 col-lg-offset-2"> <button id="refreshUsers" class="btn btn-primary">Refresh Users</button> </div> </div> - <br /> - <br /> - <br /> - <br /> + <div> </div> <div class="form-group"> @@ -137,7 +133,7 @@ dataType: "json", success: function (response) { if (response.length > 1) { - $(response).each(function(user) { + $(response).each(function() { $('#users').append("<option>" + this + "</option>"); }); } else { diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index 82fc522bb..651a87855 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -34,7 +34,7 @@ <div class="form-group"> <label for="Ip" class="col-lg-2 control-label">CouchPotato Hostname or IP</label> <div class="col-lg-10"> - <input type="text" class="form-control" id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip"> + <input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip"> </div> </div> @@ -42,7 +42,7 @@ <label for="portNumber" class="col-lg-2 control-label">Port</label> <div class="col-lg-10"> - <input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port"> + <input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port"> </div> </div> @@ -50,7 +50,7 @@ <div class="form-group"> <label for="ApiKey" class="col-lg-2 control-label">CouchPotato API Key</label> <div class="col-lg-10"> - <input type="text" class="form-control" id="ApiKey" name="ApiKey" value="@Model.ApiKey"> + <input type="text" class="form-control form-control-custom " id="ApiKey" name="ApiKey" value="@Model.ApiKey"> </div> </div> diff --git a/PlexRequests.UI/Views/Admin/Settings.cshtml b/PlexRequests.UI/Views/Admin/Settings.cshtml index 2f09f59cc..d5f4a1b70 100644 --- a/PlexRequests.UI/Views/Admin/Settings.cshtml +++ b/PlexRequests.UI/Views/Admin/Settings.cshtml @@ -13,14 +13,14 @@ } <div class="col-sm-8"> - <form class="form-horizontal" method="POST" action="/admin/couchpotato" id="mainForm"> + <form class="form-horizontal" method="POST" action="/admin" id="mainForm"> <fieldset> <legend>Request Plex Settings</legend> <div class="form-group"> <label for="portNumber" class="col-lg-2 control-label">Port</label> <div class="col-lg-10"> - <input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port"> + <input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port"> </div> </div> <small class="col-lg-10 col-lg-offset-2">You will have to restart after changing the port.</small> @@ -58,9 +58,9 @@ <div class="form-group"> <label for="WeeklyRequestLimit" class="col-lg-2 control-label">Weekly Request Limit</label> - <div class="col-lg-10 checkbox"> + <div class="col-lg-10"> <label> - <input type="number" id="WeeklyRequestLimit" name="WeeklyRequestLimit" value="@Model.WeeklyRequestLimit"> + <input type="number" id="WeeklyRequestLimit" name="WeeklyRequestLimit" class="form-control form-control-custom " value="@Model.WeeklyRequestLimit"> </label> </div> </div>