Skip to content

Commit

Permalink
Cleaned up the modules a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodejunkie committed Feb 15, 2013
1 parent 617c9c6 commit 3433a94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
36 changes: 2 additions & 34 deletions src/Nancy.Demo.Samples/Modules/Home.cs
@@ -1,49 +1,17 @@
namespace Nancy.Demo.Samples.Modules
{
using System;
using Authentication.Forms;

public class Home : NancyModule
{
public Home(IUserDatabase userDatabase)
public Home()
{
Get["/"] = parameters =>
{
var user = Context.CurrentUser;
{
return View["index"];
};

Get["/about"] = parameters => {
return View["about"];
};

Get["/login"] = x =>
{
return View["login"];
};

Post["/login"] = parameters => {
var userGuid = userDatabase.ValidateUser((string)this.Request.Form.Password);
if (userGuid == null)
{
//return this.Context.GetRedirect("~/login?error=true&username=" + (string)this.Request.Form.Username);
return Response.AsRedirect("/");
}
DateTime? expiry = null;
//if (this.Request.Form.RememberMe.HasValue)
//{
// expiry = DateTime.Now.AddDays(7);
//}
return this.LoginAndRedirect(userGuid.Value, expiry);
};

Get["/logout"] = x => {
return this.LogoutAndRedirect("~/");
};
}
}
}
29 changes: 28 additions & 1 deletion src/Nancy.Demo.Samples/Modules/Login.cs
@@ -1,9 +1,36 @@
namespace Nancy.Demo.Samples.Modules
{
using System;
using Authentication.Forms;

public class Login : NancyModule
{
public Login()
public Login(IUserDatabase userDatabase)
{

Get["/login"] = x =>
{
return View["login"];
};

Post["/login"] = parameters =>
{
var userGuid = userDatabase.ValidateUser((string)this.Request.Form.Password);
if (userGuid == null)
{
return Response.AsRedirect("/");
}
DateTime? expiry = null;
return this.LoginAndRedirect(userGuid.Value, expiry);
};

Get["/logout"] = x =>
{
return this.LogoutAndRedirect("~/");
};
}
}
}

0 comments on commit 3433a94

Please sign in to comment.