pull/470/head
tidusjar 9 years ago
parent d843ab0ebb
commit 632ce75fa0

@ -55,6 +55,7 @@ namespace PlexRequests.Core.SettingModels
public string NoApprovalUsers { get; set; } public string NoApprovalUsers { get; set; }
public bool CollectAnalyticData { get; set; } public bool CollectAnalyticData { get; set; }
public bool IgnoreNotifyForAutoApprovedRequests { get; set; } public bool IgnoreNotifyForAutoApprovedRequests { get; set; }
public bool Wizard { get; set; }
/// <summary> /// <summary>
/// The CSS name of the theme we want /// The CSS name of the theme we want

@ -184,15 +184,25 @@ namespace PlexRequests.Core
var plexSettings = new SettingsServiceV2<PlexSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider())); var plexSettings = new SettingsServiceV2<PlexSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
var currentSettings = plexSettings.GetSettings(); var currentSettings = plexSettings.GetSettings();
if (!string.IsNullOrEmpty(auth.OldPlexAuthToken)) if (!string.IsNullOrEmpty(auth?.OldPlexAuthToken))
{ {
currentSettings.PlexAuthToken = auth.OldPlexAuthToken; currentSettings.PlexAuthToken = auth?.OldPlexAuthToken;
plexSettings.SaveSettings(currentSettings); plexSettings.SaveSettings(currentSettings);
// Clear out the old value // Clear out the old value
auth.OldPlexAuthToken = string.Empty; auth.OldPlexAuthToken = string.Empty;
authSettings.SaveSettings(auth); authSettings.SaveSettings(auth);
} }
//If we have an authToken we do not need to go through the setup
if (!string.IsNullOrEmpty(auth?.OldPlexAuthToken))
{
var prServuce = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(Db, new MemoryCacheProvider()));
var settings = prServuce.GetSettings();
settings.Wizard = true;
prServuce.SaveSettings(settings);
}
} }
/// <summary> /// <summary>

@ -94,7 +94,7 @@
success: function (response) { success: function (response) {
if (response.result === true) { if (response.result === true) {
//Next //Next
loadArea("createAdminArea"); loadArea("adminArea");
} else { } else {
generateNotify(response.message, "warning"); generateNotify(response.message, "warning");
} }
@ -105,6 +105,7 @@
}); });
}); });
$('#contentBody').on('click', '#SearchForMovies', function () { $('#contentBody').on('click', '#SearchForMovies', function () {
var checked = this.checked; var checked = this.checked;
changeDisabledStatus($('#RequireMovieApproval'), checked, $('#RequireMovieApprovalLabel')); changeDisabledStatus($('#RequireMovieApproval'), checked, $('#RequireMovieApprovalLabel'));

@ -53,6 +53,12 @@ namespace PlexRequests.UI.Modules
private Response CheckAuth() private Response CheckAuth()
{ {
var settings = PlexRequestSettings.GetSettings(); var settings = PlexRequestSettings.GetSettings();
// Have we been through the wizard?
if (!settings.Wizard)
{
return Context.GetRedirect("~/wizard");
}
var baseUrl = settings.BaseUrl; var baseUrl = settings.BaseUrl;
var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin"; var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin";

@ -24,10 +24,13 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nancy; using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Extensions;
using Nancy.ModelBinding; using Nancy.ModelBinding;
using Nancy.Responses.Negotiation; using Nancy.Responses.Negotiation;
using Nancy.Validation; using Nancy.Validation;
@ -43,31 +46,35 @@ namespace PlexRequests.UI.Modules
public class UserWizardModule : BaseModule public class UserWizardModule : BaseModule
{ {
public UserWizardModule(ISettingsService<PlexRequestSettings> pr, ISettingsService<PlexSettings> plex, IPlexApi plexApi, public UserWizardModule(ISettingsService<PlexRequestSettings> pr, ISettingsService<PlexSettings> plex, IPlexApi plexApi,
ISettingsService<AuthenticationSettings> auth) : base("wizard", pr) ISettingsService<AuthenticationSettings> auth, ICustomUserMapper m) : base("wizard", pr)
{ {
PlexSettings = plex; PlexSettings = plex;
PlexApi = plexApi; PlexApi = plexApi;
PlexRequestSettings = pr; PlexRequestSettings = pr;
Auth = auth; Auth = auth;
Mapper = m;
Get["/"] = x => Index(); Get["/", true] = async (x, ct) =>
{
var settings = await PlexRequestSettings.GetSettingsAsync();
if (settings.Wizard)
{
return Context.GetRedirect("~/search");
}
return View["Index"];
};
Post["/plexAuth"] = x => PlexAuth(); Post["/plexAuth"] = x => PlexAuth();
Post["/plex", true] = async (x, ct) => await Plex(); Post["/plex", true] = async (x, ct) => await Plex();
Post["/plexrequest", true] = async (x, ct) => await PlexRequest(); Post["/plexrequest", true] = async (x, ct) => await PlexRequest();
Post["/auth", true] = async (x, ct) => await Authentication(); Post["/auth", true] = async (x, ct) => await Authentication();
Post["/createuser",true] = async (x,ct) => await CreateUser();
} }
private ISettingsService<PlexSettings> PlexSettings { get; } private ISettingsService<PlexSettings> PlexSettings { get; }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; } private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<AuthenticationSettings> Auth { get; } private ISettingsService<AuthenticationSettings> Auth { get; }
private ICustomUserMapper Mapper { get; }
private Negotiator Index()
{
return View["Index"];
}
private Response PlexAuth() private Response PlexAuth()
@ -141,5 +148,22 @@ namespace PlexRequests.UI.Modules
} }
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save the settings to the database, please try again." }); return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save the settings to the database, please try again." });
} }
private async Task<Response> CreateUser()
{
var username = (string)Request.Form.Username;
var userId = Mapper.CreateAdmin(username, Request.Form.Password);
Session[SessionKeys.UsernameKey] = username;
// Destroy the Plex Auth Token
Session.Delete(SessionKeys.UserWizardPlexAuth);
// Update the settings so we know we have been through the wizard
var settings = await PlexRequestSettings.GetSettingsAsync();
settings.Wizard = true;
await PlexRequestSettings.SaveSettingsAsync(settings);
return this.LoginAndRedirect((Guid)userId, fallbackRedirectUrl: "/search");
}
} }
} }

@ -32,7 +32,7 @@
<script id="plexAuthArea" type="text/html"> <script id="plexAuthArea" type="text/html">
<form method="post" action="plexAuth" id="plexAuthForm"> <form method="post" action="/wizard/plexAuth" id="plexAuthForm">
<h4 class="media-heading landing-title">Plex Authentication</h4> <h4 class="media-heading landing-title">Plex Authentication</h4>
<div class="form-group"> <div class="form-group">
<label for="username" class="control-label">Username and Password</label> <label for="username" class="control-label">Username and Password</label>
@ -55,7 +55,7 @@
<script id="plexArea" type="text/html"> <script id="plexArea" type="text/html">
<form method="post" action="plex" id="plexForm"> <form method="post" action="/wizard/plex" id="plexForm">
<h4 class="media-heading landing-title">Plex Settings</h4> <h4 class="media-heading landing-title">Plex Settings</h4>
<div class="form-group"> <div class="form-group">
<label for="Ip" class="control-label">Plex Hostname or IP Address</label> <label for="Ip" class="control-label">Plex Hostname or IP Address</label>
@ -86,7 +86,7 @@
</script> </script>
<script id="plexRequestArea" type="text/html"> <script id="plexRequestArea" type="text/html">
<form method="post" action="plexrequest" id="plexRequestForm"> <form method="post" action="/wizard/plexrequest" id="plexRequestForm">
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<input type="checkbox" id="SearchForMovies" name="SearchForMovies"><label id="SearchForMoviesLabel" for="SearchForMovies">Allow searching for Movies</label> <input type="checkbox" id="SearchForMovies" name="SearchForMovies"><label id="SearchForMoviesLabel" for="SearchForMovies">Allow searching for Movies</label>
@ -128,7 +128,7 @@
</script> </script>
<script id="authArea" type="text/html"> <script id="authArea" type="text/html">
<form method="post" action="auth" id="authForm"> <form method="post" action="/wizard/auth" id="authForm">
<div class="form-group"> <div class="form-group">
<div class="checkbox userAuthTooltip" title="This will only allow the users that are your friends on Plex to log into Plex Requests. Note: They only need to enter their username, unless the below option is selected."> <div class="checkbox userAuthTooltip" title="This will only allow the users that are your friends on Plex to log into Plex Requests. Note: They only need to enter their username, unless the below option is selected.">
<input type="checkbox" id="userAuth" name="UserAuthentication"> <input type="checkbox" id="userAuth" name="UserAuthentication">
@ -150,3 +150,23 @@
</div> </div>
</form> </form>
</script> </script>
<script id="adminArea" type="text/html">
<form method="post" action="/wizard/createuser" id="adminForm">
<div class="form-group">
<div>
<label for="adminUsername">Username</label><input type="text" class="form-control form-control-custom" id="adminUsername" name="Username" placeholder="Username">
</div>
<br />
<div>
<label for="adminPassword">Password</label><input type="password" class="form-control form-control-custom" id="adminPassword" name="Password" placeholder="Password">
</div>
</div>
<div class="form-group">
<div style="text-align: center; margin-top: 20px">
<button id="submitAdmin" type="submit" class="btn btn-success-outline">Finish</button>
</div>
</div>
</form>
</script>
Loading…
Cancel
Save