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 bool CollectAnalyticData { get; set; }
public bool IgnoreNotifyForAutoApprovedRequests { get; set; }
public bool Wizard { get; set; }
/// <summary>
/// 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 currentSettings = plexSettings.GetSettings();
if (!string.IsNullOrEmpty(auth.OldPlexAuthToken))
if (!string.IsNullOrEmpty(auth?.OldPlexAuthToken))
{
currentSettings.PlexAuthToken = auth.OldPlexAuthToken;
currentSettings.PlexAuthToken = auth?.OldPlexAuthToken;
plexSettings.SaveSettings(currentSettings);
// Clear out the old value
auth.OldPlexAuthToken = string.Empty;
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>

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

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

@ -42,7 +42,7 @@ namespace PlexRequests.UI.Modules
public abstract class BaseModule : NancyModule
{
protected string BaseUrl { get; set; }
protected BaseModule(ISettingsService<PlexRequestSettings> settingsService)
{
@ -66,7 +66,7 @@ namespace PlexRequests.UI.Modules
BaseUrl = baseUrl;
var settingModulePath = string.IsNullOrEmpty(baseUrl) ? modulePath : $"{baseUrl}/{modulePath}";
ModulePath = settingModulePath;
Before += (ctx) =>

@ -24,10 +24,13 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Linq;
using System.Threading.Tasks;
using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Extensions;
using Nancy.ModelBinding;
using Nancy.Responses.Negotiation;
using Nancy.Validation;
@ -43,33 +46,37 @@ namespace PlexRequests.UI.Modules
public class UserWizardModule : BaseModule
{
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;
PlexApi = plexApi;
PlexRequestSettings = pr;
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["/plex", true] = async (x,ct) => await Plex();
Post["/plexrequest", true] = async (x,ct) => await PlexRequest();
Post["/auth", true] = async (x,ct) => await Authentication();
Post["/plex", true] = async (x, ct) => await Plex();
Post["/plexrequest", true] = async (x, ct) => await PlexRequest();
Post["/auth", true] = async (x, ct) => await Authentication();
Post["/createuser",true] = async (x,ct) => await CreateUser();
}
private ISettingsService<PlexSettings> PlexSettings { get; }
private IPlexApi PlexApi { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<AuthenticationSettings> Auth { get; }
private ICustomUserMapper Mapper { get; }
private Negotiator Index()
{
return View["Index"];
}
private Response PlexAuth()
{
var user = this.Bind<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." });
}
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">
<form method="post" action="plexAuth" id="plexAuthForm">
<form method="post" action="/wizard/plexAuth" id="plexAuthForm">
<h4 class="media-heading landing-title">Plex Authentication</h4>
<div class="form-group">
<label for="username" class="control-label">Username and Password</label>
@ -55,7 +55,7 @@
<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>
<div class="form-group">
<label for="Ip" class="control-label">Plex Hostname or IP Address</label>
@ -86,7 +86,7 @@
</script>
<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="checkbox">
<input type="checkbox" id="SearchForMovies" name="SearchForMovies"><label id="SearchForMoviesLabel" for="SearchForMovies">Allow searching for Movies</label>
@ -128,7 +128,7 @@
</script>
<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="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">
@ -149,4 +149,24 @@
</div>
</div>
</form>
</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