Started the user auth

pull/13/head
tidusjar 9 years ago
parent 48fd182e52
commit a8b6137ef8

@ -4,6 +4,7 @@ using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Bootstrapper;
using Nancy.Diagnostics;
using Nancy.Session;
using Nancy.TinyIoc;
using RequestPlex.Core;
@ -40,7 +41,9 @@ namespace RequestPlex.UI
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
CookieBasedSessions.Enable(pipelines);
StaticConfiguration.DisableErrorTraces = false;
base.ApplicationStartup(container, pipelines);
// Enable forms auth

@ -0,0 +1,33 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SessionKeys.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.UI.Models
{
public class SessionKeys
{
public const string UsernameKey = "Username";
}
}

@ -26,7 +26,7 @@
#endregion
using System.Dynamic;
using System.Linq;
using System.Web.UI;
using Nancy;
using Nancy.Extensions;
using Nancy.ModelBinding;

@ -28,12 +28,11 @@ namespace RequestPlex.UI.Modules
Post["/login"] = x =>
{
var userId = UserMapper.ValidateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
var userId = UserMapper.ValidateUser((string)Request.Form.Username, (string)Request.Form.Password);
if (userId == null)
{
return this.Context.GetRedirect("~/login?error=true&username=" + (string)this.Request.Form.Username);
return Context.GetRedirect("~/login?error=true&username=" + (string)Request.Form.Username);
}
DateTime? expiry = null;
if (Request.Form.RememberMe.HasValue)
@ -63,8 +62,6 @@ namespace RequestPlex.UI.Modules
var userId = UserMapper.CreateUser(Request.Form.Username, Request.Form.Password);
return this.LoginAndRedirect((Guid)userId);
};
}
}
}

@ -50,7 +50,7 @@ namespace RequestPlex.UI.Modules
Post["/delete"] = _ =>
{
var convertedType = (string)Request.Form.type == "movie" ? RequestType.Movie : RequestType.TvShow;
return Delete((int)Request.Form.id, convertedType);
return DeleteRequest((int)Request.Form.id, convertedType);
};
}
@ -106,7 +106,7 @@ namespace RequestPlex.UI.Modules
return Response.AsJson(viewModel);
}
private Response Delete(int tmdbId, RequestType type)
private Response DeleteRequest(int tmdbId, RequestType type)
{
var currentEntity = Service.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId && x.Type == type);
Service.Delete(currentEntity);

@ -0,0 +1,56 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UserLoginModule.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 Nancy;
using RequestPlex.UI.Models;
namespace RequestPlex.UI.Modules
{
// TODO: Check the settings to see if we need to authenticate
// TODO: Add ability to logout
// TODO: Create UserLogin page
// TODO: If we need to authenticate we need to check if they are in Plex
// TODO: Allow the user of a username only or a Username and password
public class UserLoginModule : NancyModule
{
public UserLoginModule() : base("userlogin")
{
Get["/"] = _ => View["Index"];
Post["/"] = x => LoginUser();
}
private Response LoginUser()
{
var username = Request.Form.username;
// Add to the session
Request.Session[SessionKeys.UsernameKey] = username;
return Response.AsJson("");
}
}
}

@ -48,21 +48,13 @@ namespace RequestPlex.UI
s.SetupDb();
var uri = GetStartupUri();
try
{
using (WebApp.Start<Startup>(uri))
{
Console.WriteLine($"Request Plex is running on {uri}");
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
catch (Exception e)
using (WebApp.Start<Startup>(uri))
{
throw;
Console.WriteLine($"Request Plex is running on {uri}");
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
private static void WriteOutVersion()

@ -131,8 +131,10 @@
</Content>
<Compile Include="Models\PlexAuth.cs" />
<Compile Include="Models\RequestViewModel.cs" />
<Compile Include="Models\SessionKeys.cs" />
<Compile Include="Modules\AdminModule.cs" />
<Compile Include="Modules\IndexModule.cs" />
<Compile Include="Modules\UserLoginModule.cs" />
<Compile Include="Modules\LoginModule.cs" />
<Compile Include="Modules\RequestsModule.cs" />
<Compile Include="Modules\SearchModule.cs" />
@ -219,6 +221,9 @@
<Content Include="Views\Admin\CouchPotato.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\UserLogin\Index.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

@ -0,0 +1,7 @@
<form method="POST">
Username <input class="form-control" type="text" name="Username"/>
<br/>
Password <input class="form-control" name="Password" type="password"/>
<br/>
<input class="btn btn-success" type="submit" value="Login"/>
</form>
Loading…
Cancel
Save